Unexpected Type Error on simple setBool(bool) method

Hello,

I get a random error on my published face (reported by ERA).

An Unexpected Type Error that I don't understand...

Here is an extract of my code:

// View.mc
class View extends Ui.WatchFace {
    private var burn as Boolean;
    private var aod as Boolean;

    private var dr as Drawer;

    function initialize() {
        WatchFace.initialize();
        aod = false;
        burn = false;
    }

    function onLayout(dc as Dc) as Void {
        dr = new Drawer(dc);
        burn = System.getDeviceSettings() has :requiresBurnInProtection and System.getDeviceSettings().requiresBurnInProtection;
    }

    function onEnterSleep() as Void {
        aod = true;
        dr.setSleepMode(aod and burn); // <-- Unexpected Type Error on this line
        Ui.requestUpdate();
    }
}

// Drawer.mc
class Drawer {
    private var _dc as Dc;
    private var _sleepMode as Boolean;

    function initialize(dc as Dc) {
        _dc = dc;
        _sleepMode = false;
    }

    function setSleepMode(sleepMode as Boolean) as Void {
        _sleepMode = sleepMode;
    }
}

Can you see what is going on? Could the variable burn become null at some point?

Top Replies

All Replies

  • You can also semi-confirm this theory by looking at the ERA.

    1) If it's the case that dr is null in when dr.setSleep() is called, the error message should look like this:

    Error: Unexpected Type Error
    Details: Failed invoking <symbol>

    2) If it's the case that (somehow) (aod and burn) is the culprit, the error message should look a bit different:

    Error: Unhandled Exception
    Exception: UnexpectedTypeException: Expected Number/Boolean/Long, given null/Boolean

    I came up with these error messages by using little toy examples in the sim, which imo, is a better way to initially try to confirm theories like this, since it doesn't rely on updating your app in the store. Like, if I really thought "and" was broken, I would write a bunch of test cases in a toy app, and see if it breaks in the sim. Then I might try it on a real device of mine. Only after doing both of those things (and not gaining any useful information) would I push a change to the store, because obviously it takes a lot more time to get confirmation back in that case.

    Code for 1):

    var x = null;
    x.foo(); // "foo" is a known symbol bc something in the SDK uses it, I think, but you could use any known symbol

    Code for 2):

    var y = true && null;

  • You do thing in onLayout that should be done in initialise because you want to save dc without any reason... I'll do some test to know if it's possible to draw something out of onUpdate.

    Era often shows bad line number.

  • The problem is that it touches also onExitSleep().

    And of course there is no info in doc.