Unexpected Type/Invalid Value errors when using WatchUi.getCurrentView()

I am still working through a few issues I am seeing in the ERA viewer for my app, and I have come across another one where I would appreciate some input from the community.

In my app, I have a class ErrorView, which is a full-screen view used to display error messages. The class contains helper functions that use WatchUi.getCurrentView() to determine whether an error view is currently being shown.

In all my local tests, this works reliably under various conditions, including calls made during getInitialView(), where no view has been pushed yet.

However, there are reports of an Invalid Value error and an Unexpected Type Error occurring on a Fenix 8 Pro and an Edge 1040. These errors occur during startup and at another, later point.

Below is the relevant code with line numbers:

38 // Returns the error view if is shown, or otherwise null
39 private static function get() as ErrorView? {
40     var view = WatchUi.getCurrentView()[0];
41     if( view instanceof ErrorView ) {
42         return view;
43     } else {
44         return null;
45     }
46 }
47
48 // Determins whether an error view is currently showing
49 public static function isShowing() as Boolean {
50     return WatchUi.getCurrentView()[0] instanceof ErrorView;
51 }

And here are the corresponding errors with stack traces from the ERA viewer:

Error Name: Invalid Value
Devices:
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.12
Backtrace:
    ErrorView.<globals/ErrorView/<statics>/<>get>:40
    ErrorView.createOrUpdate:26
    OHApp.getInitialView:76

Error Name: Unexpected Type Error
Devices:
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.12
Backtrace:
    ErrorView.<globals/ErrorView/<statics>/<>get>:41
    ErrorView.createOrUpdate:26
    OHApp.getInitialView:76

Error Name: Unexpected Type Error
Devices:
    Edge® 1040 / 1040 Solar: 30.12
Backtrace:
    ErrorView.isShowing:50
    SitemapRequestTasks.invoke:188
    AsyncTaskQueue.executeTasks:119

In all three cases, the errors occur either when accessing WatchUi.getCurrentView() or when checking the type of its result using instanceof. Since these helper functions do not do much beyond that, the line references reported by ERA seem accurate.

What I do not understand is under which circumstances WatchUi.getCurrentView() or an instanceof check could result in these errors.

Any hints or ideas would be very welcome.

For reference, here is the full source file:
https://github.com/openhab/openhab-garmin/blob/main/source/user-interface/error-handling/ErrorView.mc

Regards, Robert

  • I have one more error that might be related to this. I’m seeing another Invalid Value exception in a line that calls getCurrentView(), so it could be tied to the same underlying issue.

    Error Name: Invalid Value
    Occurrences: 1
    First Occurrence: 2026-01-14
    Last Occurrence: 2026-01-14
    Devices:
        Edge® 1040 / 1040 Solar: 30.12
    App Versions: v1.1.2.1
    Languages: fre
    Backtrace:
        BasePageMenuInitializationTasks.invoke:89
        AsyncTaskQueue.executeTasks:119

    The error occurs in the following if statement. The equals function used is the standard Object.equals() implementation.

    if( _pageMenu.equals( WatchUi.getCurrentView()[0] ) ) {
    }