Unexpected Type Error

I read lots of the old threads about Unexpected Type Error and how Properties.getValue can return null. My problem resembles that, but I still can't figure out what is the problem.

My code is:

function getConfig(key as PropertyKeyType) as PropertyValueType? {
  var val; // this is the line I get the error according to ERA
  try {
    val = Properties.getValue(key);
  } catch (e) {
    logRelease(key + ":" + e.getErrorMessage());
    val = null;
  }
  return val;
}

And this is the error from ERA:

Error Name: Unexpected Type Error
Occurrences: 7
First Occurrence: 2024-01-17
Last Occurrence: 2024-01-22
Devices:
    vívoactive® 4S: 7.80
App Versions: 2.3.1
Languages: pol
Backtrace:
    Config.getConfig:18
    Config.getConfigNumber:93
    MyApp.onStop:122 

So what I know is that the error is in getConfig. And before you point me to the best practices to check for null and type, all that code is in getConfigNumber().
Because the call comes from MyApp.onStop:122, I even know that key = "i" so I believe even the
key + ":" + e.getErrorMessage()
can't be the problem (all 3 are strings)

However I can't understand then what can be the problem in the last line that makes sense:
val = Properties.getValue(key);

the value of the i property is supposed to be a number, but even if it isn't (and that would be taken care of in getConfigNumber) whatever the type of the property is, including null, I can't understand how the above line (or any other line in getConfig() can cause an Unexpected Type Error.

  • That is exactly what my code I posted above does, and if you would've looked at my code then you would not only see that but also that I get the error on the Properties.getValue("i") call, and that such property is defined, and that even though it's in try/catch it's not caught. So I don't see what else I can do, other than waiting for Garmin to fix the problem (see the link in my previous comment, from 5 months ago)

  • Resetting settings is rather sim 'features'. I think on device there is merging and new properties will get default values.

  • I've not seen it myself, but others have reported that changing the xml and uploading a new version has had issues.  It could have to do with not having a setting for every property (as I said, I aways have a setting if I have a property)

    When an iq file is built, a json files for settings is included for when you modify app settings from a phone or GE.

  • Again: I'm not "using" the value yet! Look, all I have is:

    function getConfig(key) {
       var val;
       val = Properties.getValue(key); // Error in this line!!!!!!
       ...

    key is "i", so it's a String. The value in the storage is set by saving the changes in ConnectIQ app or Garmin Express. According to the properties i is number and according to the settings i is numeric.

    And the problem can be reproduced in simulator as well in certain cases, just by opening the settings, and saving it (without changing any value).

    And it's not crashing when I save the settings, only when I try to read the value of "i" from onSettingsChanged()

    It looks as saving the settings corrupts the data in storage.

  • I seem to recall that on some devices, case wasn't used for property keys so "I' and "i" were the same.  Also, from the code you posted you only have a setting for one of your two properties,  Add a setting for both

    Who else has seen this issue, as it seems it's unique to you.

  • I know about that claim, and it might be true on some devices, but certainly not on fr245. Just checked and it does return the correct values (I also have "d" and "D" and both are used to display settings, so it's easy to see).

    I will not add settings for "I", because as I explained above it's being written and read by code, and should not be settable by the user. In new devices it could be written to storage, but since I support devices line epix and fr230 I had to add them to properties.

    I agree that in some way it is unique to my app and maybe even to some other circumstances. I also am pretty sure that it doesn't happen to all users using the same devices (just because I can see the device usage percentages and out of 190k users there must be many using each device, and I have only a small amount of problems reported in ERA) Still I'd like to be able to fix this.

    I am starting to suspect that somehow this can be related to memory size. I added some new code and while I did some debugging and when I read the config I see I have more free memory than I have when reading other config values when the app starts, I am not that sure about the way it works when the settings are being saved. Can it be that saving the settings runs the app and then it reaches some memory limit and it crashes and somehow corrupts the storage and also it doesn't give any indication in ConnectIQ app?

  • Error Name: Unhandled Exception
    Occurrences: 18
    First Occurrence: 2024-06-08
    Last Occurrence: 2024-07-15
    Devices:
        fēnix® 6 Pro / 6 Sapphire / 6 Pro Solar / 6 Pro Dual Power / quatix® 6: 27.00
        Venu® 3: 10.20
        Forerunner® 165: 19.18
        fēnix® 7 Pro: 17.28
    App Versions: 3.8.0
    Languages: cht, deu, eng, pol


    Error Name: Unhandled Exception
    Occurrences: 3
    First Occurrence: 2024-06-20
    Last Occurrence: 2024-06-20
    Devices:
        vívoactive® 4S: 8.30
    App Versions: 3.8.0
    Languages: ces

    All those error is when reading properties when app doesn't fully starts and probably only for first time after update/installing.

    I can't reproduce it in my system unless I fill memory - so it means - full memory, no properties loaded and Unhandled Exception.

    If you can reproduce crash move reading properties to e.g. onUpdate and test.

  • I get "Unexpected Type Error". You get "Unhandled Exception", which to me hints that you should add a try around that part of the code. But it's not that simple, I also get this exception in some app, and because I can't reproduce I can't really do much about it other than catching and more or less that's it. It doesn't necessarily (most probably not) improves the user experience. True they won't see a crash, but they won't see the expected results either...

    Regarding the error I got, even though I reproduced it on my son's device didn't help me yet to fix it because I can't catch it nor am I being able to explain it so I can't do much about it. The only thing I haven't tried yet, and I'll try to do tomorrow is to remove a big chunk of the code to make sure there's no memory limit in play and re-testing. 

  • I have also type error

    Error Name: Unexpected Type Error
    Occurrences: 2
    First Occurrence: 2023-04-22
    Last Occurrence: 2023-04-29
    Devices:
    Upcoming Wearable: 12.13
    Venu® 2 Plus: 12.14
    App Versions: 3.1.0
    Languages: chs, cht
    Backtrace:
    PSX1_Utils.getValue_v1:905

    Error Name: Unexpected Type Error
    Occurrences: 1
    First Occurrence: 2024-05-12
    Last Occurrence: 2024-05-12
    Devices:
     D2Tm Delta PX: 5.30
    App Versions: 8.7.0
    Languages: chs
    Backtrace:
    PSX6_Utils.getValue_v1:871

    most of them for APAC devices

    forums.garmin.com/.../properties-getvalue-and-error-unexpected-type-error