has :timeToRecovery is true for the Venu2 Plus and crashes because, well, it's not there!

Hi, for a reason that I ignore, the body of this if statement is ran on a Venu2 Plus although this watch has no recovery time feature...

var info = ActivityMonitor.getInfo();
if (value == null && (info has :timeToRecovery)) {
    value = info.timeToRecovery; // Info time to recovery is in hours
}

Of course, it crashes because the timeToRecovery field isn't there. Am I missing something here?

PS. I can't paste as code as it says for some reason that I've been blocked when I click on Ok.

  • This didn't work either

    if (value == null && (info has :timeToRecovery) == true) {
         value = info.timeToRecovery; // Info time to recovery is in hours
    }

    But this worked.

    var t = (info has :timeToRecovery);
    if (value == null && t == true) {
        value = info.timeToRecovery; // Info time to recovery is in hours
    }

    Has to be a bug in the compiler (V1.0.11)

  • As mentioned in the other thread, the simplest explanation here is that you are running old code (which lacks the has check) instead of the latest code (which does have the has check), due to a quirk where the project isn’t being rebuilt when you use the Run command in VS Code.

    If you are indeed running in the simulator, the easiest way to verify that you’re running the latest code is to add a println statement with distinctive text (at some point before the crash) and ensure that the text is printed in the output window.

    If you are running on a real device, you could use the same technique although ofc you’d have to take the additional step of creating the requisite text file to capture println output.

    Are you seeing this in the simulator, on a real device, or both? Can you recreate the problem reliably (especially after verifying that you’re actually running the latest code when it happens)?

  • Yeah, it must have been running old code as I can't reproduce it anymore, I think my problem with not detecting changes in the code was due to an older version of VS Code on Windows I was running (1.77). I updated to the latest November release (1.96.1) and it's gone now.