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