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] ) ) {
    }
  • Hey, I've read both of your posts about this issue. I started seeing this in late December last year. I'm getting a bunch of very similar errors in some custom UI View settings classes I've made. It's seemingly an issue which has been introduced with Beta Softwares 30.xx, unsure about Fenix 8 Pro as I do not support any watches, but potentially the same issue as current Beta Software is versions 21.xx. All of my crashes are related to type checks and comparisons using "instanceof" and "if" statements, much like you, to confirm the current View. All are the Invalid Value and Unexpected Type Errors that you are also seeing. 

    From my actual testing on a Garmin Edge 840, the crash is sporadic but on certain Beta Software versions it was far more likely, e.g. Beta Softwares 30.11 - 30.15 for Edge devices. As a result I made a post about it on a beta program bug reports forum, and received a reply from Garmin albeit a month later, and they marked the issue "Acknowledged", on the same day they released Beta Software 30.17. 

    From my testing on Beta Software 30.17, it seems fixed, but I'm still seeing some instances and have a user reporting issues on Software 30.18. I've tested this, and can't really reproduce, so I'm assuming it's still the same sporadic crash as prior software versions. 

    I can't find an easy way to work around this issue, but as far as I can tell it is mostly confined to older Beta Software that is all outdated now. One frustrating part is that Garmin pushed Beta Software to a subset of non-enrolled users, breaking my app and spamming my support tickets...  

    If I find anyway to work around this issue I'll let you know, but I'm assuming Garmin are making some changes to how getCurrentView works and we're seeing a bunch of issues in Beta Software as a result. I just hope they fix it before pushing to production...