Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Failing to have HandleLog sending crash log to Slack using WWW

$
0
0
So in my work as QA, I've been adding simple tools to capture Error logs picked up during development phase and send it to Slack whenever the app nullrefs on a mobile device (iOS). Bear with me, my coding knowledge is amateurish so if I'm missing something obvious, its simply because I didn't understand it. The first implementation was straightforward, when the app crashes, it would send a POST message to Slack using Webclient, without need to get a response. This is great when I'm catching a string of logs in which I can see them all in a flow before it crashes: Example of a message: LogError1 LogError2 LogError3 However, I've been trying challenging myself to improve the way the messages are sent to Slack by editing the same message, meaning, instead of one Slack message per progress sent to Slack, I want to edit and collect all logs in one Slack message. This means I'm using an IEnumerator with WWW to send and receive the message id (ts). My problem is that when the app in development crashes, it will, instead of sending: LogError1 LogError2 LogError3 It will instead send: LogError1 Then crash. It seems the Handlelog ignores any kind of Coroutine since it will only finish the Handlelog function then crash, so I've been trying to use the www.isDone in a while loop inside Handle Log but for some reason it will get stuck in that while loop after it crashes. Same for using a while loop and counting deltatime (trying to send a message without using Coroutine), or keeping track of number of messages currently being processed and only send a new one if the amount of messages sent is equal to 0.

public static int MessagesInProgress = 0;
	private static string ts = "";
	private static string channel = "";
	private static bool firstResponse = true;
	public static IEnumerator SendCall(WWWForm message, bool threadIt = false){
		Debug.Log("Data being sent "+SlackForm.form.data);
		WWW www;
		if(SlackBot.firstResponse){
			www = new WWW( postMessageUrl, message );
		} else if (!threadIt){
			message.AddField("channel",channel);
			message.AddField("ts",ts);
			www = new WWW( updateMessageUrl, message );
		} else {
			message.AddField("channel",channel);
			message.AddField("ts",ts);
			message.AddField("thread_ts",ts);
			www = new WWW( postMessageUrl, message );
		}
        yield return www;
        if(!string.IsNullOrEmpty(www.error)) {
            Debug.Log( "Error with Slack: " + www.error );
        } else {
            Debug.Log(www.text);
			if(SlackBot.firstResponse){
				JSONObject json = new JSONObject(www.text);
				channel =  json["channel"].str;
				ts = json["ts"].str;
				SlackBot.firstResponse = false;
			}
        }
	}


	public static void HandleLog(string logString, string stackTrace, LogType type) {
		if (type == LogType.Error || type == LogType.Exception || type == LogType.Assert){
			string msg = "";
			string msgAddOn = "";
			msg += "*" + AppTitle + "* (" + Tools.CommitID() + ") logged this error after "+ LogHandler.ConvertToMinutesAndSeconds(Time.realtimeSinceStartup) + ":\n" + PlaysetPlugin.CurrentScene.Title + " " + deviceGeneration + " " + SystemInfo.operatingSystem + "\n\n" + logString + "\n\n" + stackTrace + msgAddOn;

			LogHandler.PostAndEditSameSlackMessage();
			counter= 50f;
			while(counter>=0){
				Debug.Log("Hej");
			}
		}
	}

	public static void PostAndEditSameSlackMessage(string slackText = ""){
		try {
			if (slackBot == null) {
				slackBot = new SlackBot();
			}
			WWWForm slackMessage;
			slackMessage = null;
			slackMessage = new SlackForm().GetForm();
			SlackForm.AddAttachment(Automation.Instance.tests);
			slackText += Automation.Instance.GetPrettyTestProgress();
			SlackForm.AddText(slackText+"\n"+GetBasicInfo()+"\n");
Automation.Instance.StartCoroutine(SlackBot.SendCall(slackMessage));
		}
		catch (System.Exception ex) {
			Debug.Log(ex.ToString());
		}
	}
,

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>