Acknowledged
CIQQA-3881

Critical: WatchUi.getCurrentView Causing Invalid Value and Unhandled Exception Errors

My users have been experiencing crashes that appear to be related to calls to WatchUi.getCurrentView(). Specifically, Invalid Value and Unhandled Exception errors occur when accessing the array returned by this call, and Unexpected Type errors are raised when checking the result with instanceof.

After identifying this as a potential source of the issue, I introduced a wrapper function, getCurrentViewSafe(). In this function, I decomposed the call to WatchUi.getCurrentView() into multiple steps, validating each intermediate result and verifying types before accessing them. Despite these precautions, the app continues to crash at different points within this function.

The issue seems to be concentrated on newer devices. I have not encountered it myself on my Epix Pro Gen 2. Reported affected devices include Vivoactive 6, Fenix 8, Fenix 8 Pro, Venu 4, and Forerunner 970.

The complete source file is available here:

https://github.com/openhab/openhab-garmin/blob/Release-v1.1.3/source/user-interface/view-handling/ViewHandler.mc

An example of the relevant code is shown below, along with the corresponding errors as displayed in the ERA viewer:

52: var cwArray = WatchUi.getCurrentView() as Object;
53: 
54: if( ! (cwArray instanceof Array ) ) {
55:     throw new GeneralException( "cwArray not an Array" );
56: } 
57: if( cwArray.size() != 2 ) {
58:    throw new GeneralException( "cwArray.size = " + cwArray.size() );
59 }
60:        
61: var view = cwArray[0];

Although I verify that the returned value is a valid array and perform the necessary type checks beforehand, accessing it in line 61 can still trigger the following error:

Error Name: Invalid Value
Occurrences: 1
First Occurrence: 2026-02-20
Last Occurrence: 2026-02-20
Devices:
    vívoactive® 6: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:61
    CustomBehaviorDelegate.onTap:38

 Error Name: Invalid Value
Occurrences: 3
First Occurrence: 2026-02-20
Last Occurrence: 2026-02-21
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:61
    ErrorView.isShowing:50
    SitemapRequestTasks.invoke:188
    AsyncTaskQueue.executeTasks:119

The code continues as follows:

62: if( view != null && ! ( view instanceof WatchUi.View ) ) {
63:     throw new GeneralException( "cwArray[0] not a View" );
64: }
65:

Line 62 also frequently fails with an Unexpected Type error:

Error Name: Unexpected Type Error
Occurrences: 1
First Occurrence: 2026-02-20
Last Occurrence: 2026-02-20
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:62
    ExceptionHandler.handleException:111
    SitemapRequest.handleException:114
    SitemapRequest.onReceive:190
    SitemapRequest.makeRequest:145
    SitemapRequest.start:253
    OHApp.getInitialView:53

Error Name: Unexpected Type Error
Occurrences: 41
First Occurrence: 2026-02-18
Last Occurrence: 2026-02-24
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.25
    vívoactive® 6: 16.28
    fēnix® 8 47mm / 51mm / tactix® 8 47mm / 51mm / quatix® 8 47mm / 51mm: 21.25
App Versions: v1.1.3
Languages: deu, pol
Backtrace:
    ViewHandler.getCurrentViewSafe:62
    ErrorView.isShowing:50
    SitemapRequestTasks.invoke:188
    AsyncTaskQueue.executeTasks:119

Error Name: Unexpected Type Error
Occurrences: 2
First Occurrence: 2026-02-23
Last Occurrence: 2026-02-24
Devices:
    fēnix® 8 47mm / 51mm / tactix® 8 47mm / 51mm / quatix® 8 47mm / 51mm: 21.25
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:62
    ExceptionHandler.handleException:111
    SitemapRequest.handleException:114
    SitemapRequest.onReceive:190

Error Name: Unexpected Type Error
Occurrences: 20
First Occurrence: 2026-02-03
Last Occurrence: 2026-02-24
Devices:
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.25
    Venu® X1: 16.28
    Forerunner® 970: 16.28
    Edge® 1040 / 1040 Solar: 30.15
    vívoactive® 6: 16.28
    fēnix® 8 47mm / 51mm / tactix® 8 47mm / 51mm / quatix® 8 47mm / 51mm: 21.25
App Versions: v1.1.3
Languages: deu, fre, pol
Backtrace:
    ViewHandler.getCurrentViewSafe:62
    BasePageMenuInitializationTasks.invoke:89
    AsyncTaskQueue.executeTasks:119

Error Name: Unexpected Type Error
Occurrences: 2
First Occurrence: 2026-02-24
Last Occurrence: 2026-02-24
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
App Versions: v1.1.3
Languages: rus
Backtrace:
    ViewHandler.getCurrentViewSafe:62
    ErrorView.<globals/ErrorView/<statics>/<>get>:40
    ErrorView.createOrUpdate:26
    OHApp.getInitialView:76

The code then proceeds to access the array:

66: var delegate = cwArray[1];
67: if( delegate != null && 

68:         ! ( delegate instanceof WatchUi.BehaviorDelegate
69:             || delegate instanceof WatchUi.InputDelegate
70:             || delegate instanceof WatchUi.ConfirmationDelegate
71:             || delegate instanceof WatchUi.MenuInputDelegate
72:             // || delegate instanceof WatchUi.NumberPickerDelegate
73:             || delegate instanceof WatchUi.PickerDelegate
74:             || delegate instanceof WatchUi.TextPickerDelegate
75:             || delegate instanceof WatchUi.WatchFaceDelegate
76:             || delegate instanceof WatchUi.Menu2InputDelegate
77:             || delegate instanceof WatchUi.ViewLoopDelegate ) 
78: ) {
79:     throw new GeneralException( "cwArray[1] not an input delegate" );
80: }

Again, numerous Invalid Value errors occur when accessing the array in line 66, along with Unexpected Type errors when using instanceof.

Error Name: Invalid Value
Occurrences: 1
First Occurrence: 2026-02-18
Last Occurrence: 2026-02-18
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:66
    ErrorView.isShowing:50
    SitemapRequestTasks.invoke:188
    AsyncTaskQueue.executeTasks:119

Error Name: Unhandled Exception
Occurrences: 6
First Occurrence: 2026-02-16
Last Occurrence: 2026-02-24
Devices:
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.25
    Venu® 4 45mm / D2Tm Air X15: 16.28
    Venu® X1: 16.28
    Forerunner® 970: 16.28
    fēnix® 8 47mm / 51mm / tactix® 8 47mm / 51mm / quatix® 8 47mm / 51mm: 21.25
App Versions: v1.1.3
Languages: deu, pol
Backtrace:
    ViewHandler.getCurrentViewSafe:66
    ExceptionHandler.handleException:111
    AsyncTaskQueue.executeTasks:139

Error Name: Invalid Value
Occurrences: 1
First Occurrence: 2026-02-19
Last Occurrence: 2026-02-19
Devices:
    vívoactive® 6: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:66
    BasePageMenuInitializationTasks.invoke:89
    AsyncTaskQueue.executeTasks:119

Error Name: Unexpected Type Error
Occurrences: 2
First Occurrence: 2026-02-19
Last Occurrence: 2026-02-20
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
    vívoactive® 6: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:67
    ErrorView.isShowing:50
    SitemapRequestTasks.invoke:188
    AsyncTaskQueue.executeTasks:119

Error Name: Unexpected Type Error
Occurrences: 2
First Occurrence: 2026-02-18
Last Occurrence: 2026-02-23
Devices:
    vívoactive® 6: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:67
    ExceptionHandler.handleException:111
    SitemapRequest.handleException:114
    SitemapRequest.onReceive:190
    SitemapRequest.makeRequest:145
    SitemapRequest.start:253
    OHApp.getInitialView:53

Error Name: Unexpected Type Error
Occurrences: 5
First Occurrence: 2026-02-03
Last Occurrence: 2026-02-23
Devices:
    fēnix® 8 Pro 47mm / 51mm / MicroLED / quatix® 8 Pro 47mm / 51mm: 21.25
    Forerunner® 970: 16.28
    Edge® 1040 / 1040 Solar: 30.15
    fēnix® 8 47mm / 51mm / tactix® 8 47mm / 51mm / quatix® 8 47mm / 51mm: 21.25
App Versions: v1.1.3
Languages: deu, fre, pol
Backtrace:
    ViewHandler.getCurrentViewSafe:67
    BasePageMenuInitializationTasks.invoke:89
    AsyncTaskQueue.executeTasks:119

The function then returns the array:

81:
82: return cwArray as [ WatchUi.View or Null, WatchUi.InputDelegates or Null ];

In some cases, this has also resulted in Unhandled Exception errors.

Error Name: Unhandled Exception
Occurrences: 5
First Occurrence: 2026-02-16
Last Occurrence: 2026-02-22
Devices:
    Venu® 4 45mm / D2Tm Air X15: 16.28
    vívoactive® 6: 16.28
App Versions: v1.1.3
Languages: deu
Backtrace:
    ViewHandler.getCurrentViewSafe:82
    ExceptionHandler.handleException:111
    AsyncTaskQueue.executeTasks:139

  • Also in my case, proper try/catch blocks are in place. Most calls occur well after onShow(). In fact, I also call it during initialization, when no view is present on the view stack, and it has never crashed in that situation. The crashes have only occurred in cases where there was definitely a view on the stack.

    As an initial workaround, I implemented my own view stack and retrieve the current view from there instead. I am now waiting for user feedback to determine whether this resolves the issue. Unfortunately, I do not have access to an affected device to test it myself.

  • Interesting thoughts. I checked in my case, it's in compute of a datafield. I use it when I need to call DataField.showAlert and I check if maybe it's already the top view (in that case I update it instead of showAlert)

    According to the log in the simulator the order of the calls is: onLayout, onShow, compute, onUpdate. So it looks like it should be OK, but maybe in the few occasions when this error happens it's really in the 1st compute? Though since even that is supposed to be after onShow, it should theoretically be OK.

    try/catch doesn't help, I already have it. Although I wouldn't know what is the caught exception, but I wouldn't see the Invalid Value in ERA.

    Delay: good idea. Unfortunately since this is a datafield, I have no timer, so I could only use the next compute cycle. Maybe I'll try, but I am a bit skeptical.....  Actually I already kind of have this in my code, 'cause this code can be reached only after 5 seconds, that is 5 compute calls.

    But maybe this can happen when the field is not visible (i.e it's on another page)?

  • The getCurrentView() crash with "invalid value" and unhandled exceptions is hitting a lot of us since the latest SDK/firmware combo. It seems to trigger mostly when called too early in the view lifecycle (like in initialize() or onShow() before the view is fully pushed) or when the view stack is in a weird state after a pop/push sequence.

    Quick things that helped some people dodge it:

    • Wrap the call in a try-catch and log the exception details.
    • Delay it slightly with a small timer (100-200 ms) after onShow().
    • Avoid calling it from background services or glance complications that might run when no view is active.

    If you're on a Fenix 8 or Epix Pro, test on simulator vs device too—sim sometimes masks the issue. Garmin usually fixes these in the next SDK drop, but posting your minimal repro code in the thread helps them prioritize. Hope it gets patched soon.

  • > Looking at the docs, I might have found the bug:

    Interesting find. In my case, however, I do not believe I am using any views that are not derived from WatchUi.View. Both CustomMenu and Menu2 inherit from it.

    And yes, getCurrentView() returns null when called inside getInitialView(), and even during the setup phase of the initial view. If I remember correctly, I observed that getCurrentView() is still null in onShow() of the initial view as well. It only becomes available in onUpdate().

  • Looking at the docs, I might have found the bug:

    getCurrentView() as [ WatchUi.View or Null, WatchUi.InputDelegates or Null ]

    vs

    pushView(view as WatchUi.Views, delegate as WatchUi.InputDelegates or Null, transition as WatchUi.SlideType) as Lang.Boolean

    So we push Views in pushView (that includes for example Menu), but in getCurrentView we're supposed to get a View (and Menu extends Object, not View).

    Usually I would guess that this is a typo in the docs, and in getCurrentView an "s" is missing from WatchUi.Views, but given these Invalid Value errors, it's even possible that this is a real bug in the firmware, and that's why it's also generated into the docs.

    Another topic, but I wonder how and when could getCurrentView return null view. What would that mean? That we're before getInitialView, or in a Background app?