So, according to ERA, a System Error was generated in the code below, but why?

So the following background running code generated a System Error on a Fenix 6X Pro at the "else if (responseCode == 408)". What makes this line different than the others? Why not the 401 line just above it???

var suffix;
if (responseCode == 200 && responseData != null) {
    :
    : reading responseData here, skipping it for the sake of simplicity here
    :
    
    suffix = "";
}
else if (responseCode == 401) {
    suffix = Application.loadResource(Rez.Strings.label_launch_widget);
}
else if (responseCode == 408) {
    suffix = Application.loadResource(Rez.Strings.label_asleep);
}
else {
    suffix = Application.loadResource(Rez.Strings.label_error) + responseCode;
}

All three string resources in the code above are defined with 'scope="background"' and the watch language was English. If I emulate this watch,it works flawlessly.

It's frustrating trying to make a program reliable when things like that happen :-<

  • I have also a lot of errors only on apac devices so I think they are connected with devices (memory, not updated firmware etc.).

    app.loadresource is from 3.1 do maybe user has the old firmware

    but I think you should simplify your code

    var bagret ={"rc" =>responsecode, "data"=>null};

    if(responsecode == 200 && data != null)

    {

    bagret["data"]=....

    }

    BAG.exit(bagret);

    and check rest on app.onBacgroundData

  • Hi, responseData is a string of 7.5 KB and I even have to read it as a string and not a dictionary on watch with 32 KB of background space so it doesn't throw a 403 error. So passing it in full to the onBackgroundData would make matter worse I believe, especially since the whole App class has to be in background space anyway.

    I just uploaded a new version that does a better job at type checking so hopefully it doesn't throw Unhandled Exception or Unexpected Type Error. Can you go back to view previous version in ERA? All I can see is the current one. I do specify in the manifext.xml that it's for 3.1 and above if it matters.

    BTW, this is the code I created for type checking, what do you think? I need it because the data returned by makeWebRequest can be sometimes of types I wasn't expecting.

    (:background)
    function validateNumber(value, defValue) {
    	if (value == null || value instanceof Lang.Boolean) {
    		return defValue;
    	}
    
    	try {
    		value = value.toNumber();
    		if (value == null) {
    			value = defValue;
    		}
    	}
    	catch (e) {
    		value = defValue;
    	}
    	return value;
    }
    
    (:background)
    function validateFloat(value, defValue) {
    	if (value == null || value instanceof Lang.Boolean) {
    		return defValue;
    	}
    
    	try {
    		value = value.toFloat();
    		if (value == null) {
    			value = defValue;
    		}
    	}
    	catch (e) {
    		value = defValue;
    	}
    	return value;
    }
    
    (:background)
    function validateString(value, defValue) {
    	if (value == null || value instanceof Lang.Boolean) {
    		return defValue;
    	}
    
    	try {
    		value = value.toString();
    		if (value == null) {
    			value = defValue;
    		}
    	}
    	catch (e) {
    		value = defValue;
    	}
    	return value;
    }
    
    (:background)
    function validateBoolean(value, defValue) {
    	if (value != null && value instanceof Lang.Boolean) {
    		try {
    			value = (value == true);
    		}
    		catch (e) {
    			value = defValue;
    		}
    		return value;
    	}
    	else {
    		return defValue;
    	}
    }
    

  • You don't to have return to app all dictionary

    bagret["data"]=... is example you can put here what you want

    bagret["temp"] =23.5;

    bagret["Windows'"]= 1;//1= open

    ....

  • It crashed again, but this time, in the if body of that 401 line, not 408 (I'm guessing a 401 (access denied) was returned this time instead of a 408 (vehicle timeout)). The crash detail is:

    Error Name: Unhandled Exception
    Occurrences: 9
    First Occurrence: 2023-04-27
    Last Occurrence: 2023-04-27
    Devices:
        DescentTm Mk2 S: 8.70
    App Versions: 7.11.7
    Languages: kor
    Backtrace:
        ServiceDelegate.onReceiveVehicleData:154

    I'm wondering if it's something to do with the language (Korean in this case) not being including, defaulting to English but the scope not being properly interpreted (ie, a CIQ bug) so it crashes not having that string in its code space.

    Edit: Well, if it's the case, it doesn't throw the exception in the Simulator, simulating that watch and Korean. CIQ according to https://developer.garmin.com/connect-iq/compatible-devices/ is 3.3.0 so shouldn't have trouble loading resources.

  • The world wide version of the descent mk2 has CIQ 3.3.1 per devices

    The APAC version (Korean), CIQ, 3.1.7 per devices

    Scoped resources are "since 3.1.0" but maybe not there on the APAC version of the descent 2

  • Thanks, where did you get the CIQ versions for the APAC version? That would be a nice troubleshooting help.

  • Followed your advice. Rewrote the ServiceDelegate, the onBackgroundData and GlanceView:onUpdate code so the service delegate and onBackgroundData simply pushes data around while the onUpdate does the real work. That way, I can use WatchUi.loadResource instead of Application.loadResource. Never had a crash in onUpdate so hopefully the crashes won't migrate there lol. It has ran fine in the simulator for both a Fenix 6X Pro (32 KB of BG) and Venu2 (64 KB of BG) with different resultCode. I need to check on both because the ServiceDelegate code is completely different for 32 KB watches than 64 KB watches. Next I'll run it on my Venu2 for the next 24 hours and see how it behaves. With any luck, I'll be able to publish it later on. Finger crossed,

  • Thanks, where did you get the CIQ versions for the APAC version? That would be a nice troubleshooting help.

    Open compiler.json for a given device and look at the partNumbers array - each array entry will have a corresponding connectIQVersion. WW vs APAC part numbers will be obvious based on the given font/language information.

    For example, descentmk2:

    .../Garmin/ConnectIQ/Devices/descentmk2/compiler.json

        ...
        "partNumbers": [
            {
                "connectIQVersion": "3.3.1",
                "firmwareVersion": 1410,
                "languages": [
                    {
                        "code": "ara",
                        "fontSet": "ww"
                    },
                    {
                        "code": "bul",
                        "fontSet": "ww"
                    },
                    {
                        "code": "ces",
                        "fontSet": "ww"
                    },
                    {
                        "code": "dan",
                        "fontSet": "ww"
                    },
                    {
                        "code": "deu",
                        "fontSet": "ww"
                    },
                    {
                        "code": "dut",
                        "fontSet": "ww"
                    },
                    {
                        "code": "eng",
                        "fontSet": "ww"
                    },
                    {
                        "code": "est",
                        "fontSet": "ww"
                    },
                    {
                        "code": "fin",
                        "fontSet": "ww"
                    },
                    {
                        "code": "fre",
                        "fontSet": "ww"
                    },
                    {
                        "code": "gre",
                        "fontSet": "ww"
                    },
                    {
                        "code": "heb",
                        "fontSet": "ww"
                    },
                    {
                        "code": "hrv",
                        "fontSet": "ww"
                    },
                    {
                        "code": "hun",
                        "fontSet": "ww"
                    },
                    {
                        "code": "ita",
                        "fontSet": "ww"
                    },
                    {
                        "code": "lav",
                        "fontSet": "ww"
                    },
                    {
                        "code": "lit",
                        "fontSet": "ww"
                    },
                    {
                        "code": "nob",
                        "fontSet": "ww"
                    },
                    {
                        "code": "pol",
                        "fontSet": "ww"
                    },
                    {
                        "code": "por",
                        "fontSet": "ww"
                    },
                    {
                        "code": "ron",
                        "fontSet": "ww"
                    },
                    {
                        "code": "rus",
                        "fontSet": "ww"
                    },
                    {
                        "code": "slo",
                        "fontSet": "ww"
                    },
                    {
                        "code": "slv",
                        "fontSet": "ww"
                    },
                    {
                        "code": "spa",
                        "fontSet": "ww"
                    },
                    {
                        "code": "swe",
                        "fontSet": "ww"
                    },
                    {
                        "code": "tur",
                        "fontSet": "ww"
                    },
                    {
                        "code": "ukr",
                        "fontSet": "ww"
                    }
                ],
                "number": "006-B3258-00"
            },
            {
                "connectIQVersion": "3.1.7",
                "firmwareVersion": 200,
                "languages": [
                    {
                        "code": "eng",
                        "fontSet": "ww"
                    },
                    {
                        "code": "ind",
                        "fontSet": "ww"
                    },
                    {
                        "code": "zsm",
                        "fontSet": "ww"
                    },
                    {
                        "code": "zhs",
                        "fontSet": "apac_chn"
                    },
                    {
                        "code": "zht",
                        "fontSet": "apac_twn"
                    },
                    {
                        "code": "jpn",
                        "fontSet": "apac_jpn"
                    },
                    {
                        "code": "kor",
                        "fontSet": "apac_kor"
                    },
                    {
                        "code": "tha",
                        "fontSet": "apac_tha"
                    },
                    {
                        "code": "vie",
                        "fontSet": "apac_vie"
                    }
                ],
                "number": "006-B3702-00"
            }
        ],
        ...

  • Thanks. Completely forgot to check there.

  • The device folder for the descent mk2 in compiler,json file.