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?