Unhandled Exception for Watch Face Background Temporal Event Position

I get an 'Unhandled Exception' error with no details when I run a temporal event in the background of a watch face. I have no problem in the simulator; I am getting the error on a VA3M, in the CIQ_LOG.YML file. I know the error has to do with the temporal event because it happens at 5 min intervals.

In the temporal event, I am getting external weather data based on position (OpenWeatherMap). I think the error occurs when the watch does not have position data because after I use an activity to get a GPS reading, it is fine and the error does not happen again. I can replicate the error on the device after turning it off and back on (presumably clearing position data). I cannot produce the error in the simulator because the simulator defaults to (lat, lon) = (0, 0), which are actual coordinates and not a null value. (Why doesn't the simulator have a null value?)

I tried checking for a null position value using the code below, but it did not work. I am caching location data in storage. This code block is prior to Comm.makeWebRequest() within a makeRequest() function:

		var positionInfo = Position.getInfo();
		var latlon;
		
		if (positionInfo has :position && positionInfo.position != null) {
	        latlon = positionInfo.position.toDegrees();
		}
		else {
			latlon = null;
		}
		
		if ((latlon == null) or ((latlon[0] == 0) and (latlon[1] == 0))) {
			var latlonCache = Storage.getValue("latlonCache");
			
			if (latlonCache != null) {
				latlon = latlonCache;
			}
			else {
				Sys.println("latlon: " + latlon + ", latlonCache: " + latlonCache + ", Background.exit(gpsError)");
		        var gpsError = {
					"timestamp" => Time.now().value(),
					"data" => {"main" => {"temp" => "GPS"}, "dt" => Time.now().value()}
				};				
				Background.exit(gpsError);
			}
		}
		else {
			Storage.setValue("latlonCache", latlon);
		}

What am I doing wrong?

  • On thing is that in a background service, you can't save to Storage on all devices.  I think that's only possible with a 3.2 VM or newer (line 27).

    What is the line number given for the crash?

    The way I handle this, is the watch face itself is the one that saves the location if it's available, and the background uses it or returns an error if it's not available.

  • I forgot it is not possible save to storage in the background on all devices. I just tried moving the Storage.setValue command (with Position.getInfo) to the View file, and it did not work. The watch face is still crashing with the same error, which makes sense because my VA3M was already using CIQ 3.2+.

    Something else strange -- when I navigate the settings on the watch itself, it says I'm using CIQ 3.2.0, but in the YML file it says I'm using 3.2.1. I wonder if this is a bug? 

    I do not see the line number in the CIQ_LOG.YML file. Here is what I see:

    Error: Unhandled Exception
    Time: 2021-01-04T08:25:33Z
    Part-Number: 006-B2988-00
    Firmware-Version: '6.00'
    Language-Code: eng
    ConnectIQ-Version: 3.2.1
    ...
    Stack: 
      - pc: 0x10002741
      - pc: 0x100035fd
      - pc: 0x1000303e

  • 3.2.0 vs 3.2.1 

    One is what's running on the watch, the other, the SDK used to build the app

    To understand the stack, see

    forums.garmin.com/.../so-you-have-a-ciq_log-file-but-all-you-see-is-pc-without-a-friendly-stack-trace---what-to-do

  • Thanks for the info Jim! I see now how the debug works, and I was able to figure it out. Works now.

    3.2.0 vs 3.2.1 -- The SDK I'm using to build the app is actually 3.2.2. Maybe it's a bug in the SDK? The root directory in the Eclipse properties is "connectiq-sdk-mac-3.2.2-2020-08-28-a50584d55".

    I'm using Mac OS Big Sur, and the simulator does not work with 3.2.3, so I manually went back to 3.2.2. See also:

    forums.garmin.com/.../simulator-crash-on-start-on-macso-big-sur