feelsLikeTemperature null error showing up on ERA. Bug or something wrong?

Hi everyone!

Asking for help here, since I've gone through the API docs and done a lot of different changes to try and solve this issue, but at this point I don't know what to do anymore. In a matter of a few hours, I'm getting 17 error reports on ERA on different watch models as below:

Error Name: Null Reference Error
Occurrences: 17
First Occurrence: 2022-10-08 (updated it today to add the null check together with the has condition that already existed)
Last Occurrence: 2022-10-08
Devices:
fēnix® 6 Pro / 6 Sapphire / 6 Pro Solar / 6 Pro Dual Power / quatix® 6: 23.10
Venu 2: 10.22
fēnix® 6X Pro / 6X Sapphire / 6X Pro Solar / tactix® Delta Sapphire / Delta Solar / Delta Solar - Ballistics Edition / quatix® 6X / 6X Solar / 6X Dual Power: 23.10
epix (Gen 2) / quatix® 7 Sapphire: 9.36
Venu 2S: 9.22
Venu® Sq. Music Edition: 4.10
Forerunner® 955 / Solar: 12.23
Forerunner® 245 Music: 11.60
Venu: 7.20
fēnix® 7S: 9.36
fēnix® 7X / tactix® 7 / quatix® 7X Solar / Enduro 2: 8.37
Forerunner® 255 Music: 12.23
Venu 2 Plus: 10.20
Languages: cht, deu, eng, fre, ind, ita, rus, spa

The exact line of code is the one about feelsLikeTemperature below:

function initialize() {

 WatchFace.initialize();

 var variable=false;
 if (Toybox has :Weather){
  ...
  if (Toybox.Weather has :getCurrentConditions){
   ...
   if (Toybox.Weather.getCurrentConditions() has :feelsLikeTemperature and Toybox.Weather.getCurrentConditions().feelsLikeTemperature!=null) {
    variable=true;
   }
  }
 }
 ...
}


I know that sometimes the weather station returns null on the feels like temperature, but would my code above not already test that? Not sure exactly why there is still a null error being thrown. But I use that watch face daily and my weather station doesn't have that issue, and it's also something that I couldn't reproduce on the simulator.

Any help would be much appreciated!
  • You want to check fellsLikeTemperature for null,  Feels Like might not be available.

    Infact, you want to check everything in current conditions for null:

    https://developer.garmin.com/connect-iq/api-docs/Toybox/Weather/CurrentConditions.html

    From the API doc:

  • Thanks , but I had noticed that on the "feels like" API docs, so that's why I'm doing both checks (has and null) on row 10 of the code. Unless you suggest another way of doing that?

    To be honest, I'm not checking the get current conditions for null (only has on this one) since I only support sdk 3.2 and above (which has weather), but I guess I'll give this a try, together with other suggestions that I might get from this post.

  • Where do you check if currentConditions itself isn't null?  That will happen if the garmin hasn't gotten weather from the phone.  You really don't need the has checks, but you do need to check for null.

    I do a single has check for this (in initialize) if(Toybox has :Weather)

    and then set a boolean.  After that, just null checks for the data.

  • I check for null on the currentConditions inside the onUpdate, before showing the value on screen. But since I'm checking the "has" condition for the feelsLike inside the initialize as well, then I guess I'll also need to check for currentConditions null inside the initialize, or move the complete feelsLike checks (has and null) for the onUpdate as well.

    Now that I think of it, I'm currently checking the "has feelsLike" inside the initialize because I thought that not all watches on 3.2 would support it, but I think you're right. If they have the currentConditions, I don't need to check has again for the feelsLike, only check for null inside the onUpdate.

    I'll give it a try and report back, thanks  

  • in onUpdate:

    var hasWeather=false;
    
    function initialize() {
        hasWeather=(Toybox has :Weather);
    }
    
    
    function onUpdate(dc) {
        if(hasWeather) {
            var cc=getCurrentConditions();
            if(cc!=null) {
                var feels=cc.feelsLikeTemperature;
                if(feels!=null) {
                    System.println("feels like "+feels);
                }
            ]
        }
    ]