Skip to content

feat: Opt-in surfacing of input, dispatcher, and resource-lookup errors - #23281

Open
MartinZikmund wants to merge 31 commits into
masterfrom
dev/mazi/inputswallow
Open

MartinZikmund wants to merge 31 commits into
masterfrom
dev/mazi/inputswallow

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented May 18, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #19197

PR Type:

✨ Feature

What changed? 🚀

Current behavior

Three classes of bugs in Uno-based apps look like "the UI did nothing" because the framework silently swallows the exception:

  • Exceptions thrown by pointer-input event handlers (RaisePointerEvent, SafeRaiseEvent, SafeRaiseTunnelingEvent, InputManager.OnTopLevelFatalError) are caught and logged.
  • Exceptions thrown by dispatcher work items (NativeDispatcher.RunAction, DispatchItemsToChoreographer) are caught and logged.
  • {StaticResource Foo} / {ThemeResource Foo} lookups that resolve to nothing only log "Couldn't statically resolve resource Foo"; the property silently stays at its default.

WinUI does the opposite in all three cases: it raises Application.UnhandledException and FAIL_FASTs on input failures, lets dispatcher work items propagate to the platform pump, and throws Microsoft.UI.Xaml.Markup.XamlParseException (HRESULT E_FAIL / AG_E_PARSER_FAILED_RESOURCE_FIND) on missing resources.

New behavior

Three opt-in feature flags, default off (no behavior change for existing apps):

Flag Effect
FeatureConfiguration.UnhandledExceptionHandling.PropagateInputExceptions A throwing routed-event handler is reported through Application.UnhandledException. If the app marks it Handled = true, the event keeps routing to the remaining handlers and ancestors (WinUI: DXamlCore::FireEvent reports, CEventManager keeps raising); otherwise it is re-thrown. Each exception is reported once, even when it unwinds through several catch sites.
FeatureConfiguration.UnhandledExceptionHandling.PropagateDispatcherExceptions NativeDispatcher.RunAction and DispatchItemsToChoreographer raise Application.UnhandledException; if unhandled, the exception propagates to the platform message pump (WinUI: FinalUnhandledErrorDetected → ErrorHelper::ProcessUnhandledError → FAIL_FAST).
FeatureConfiguration.ResourceResolution.ThrowOnUnresolvedResource Unresolved resource keys fail like WinUI's AG_E_PARSER_FAILED_RESOURCE_FIND. A {StaticResource} or {ThemeResource} still unresolved once its owner is loaded throws XamlParseException (WinUI throws at parse; Uno resolves these later). A {ThemeResource} whose pinned dictionary and the global theme resources lack the key for a newly applied theme throws COMException 0x800F1000 from the theme change (e.g. the RequestedTheme setter), without falling back to application resources. Behaviour verified against a WinAppSDK 2.5.1 probe.

Supporting changes:

  • New Application.RaiseUnhandledException helper + RaiseUnhandledExceptionOrThrow extension. Existing RaiseRecoverableUnhandledException is unchanged and still used by animations, drag/drop, etc.
  • Microsoft.UI.Xaml.Markup.XamlParseException (and Windows.UI.Xaml.Markup.XamlParseException) promoted from [NotImplemented] stub to a real exception type with the three standard constructors.
  • SamplesApp turns on all three flags by default, so latent crashes surface during Uno Platform development. Full Skia suite (12,413 tests) with all three flags on: every failure also fails on master or passes in isolation (focus/keyboard injection contention); no resource throws outside StyleHelper.UseUwpStyles(), which removes the Fluent resources from a live app (a WinUI crash too) and now suspends the flag for its scope.

Latent bugs surfaced (and fixed) by turning the flags on

Flipping PropagateInputExceptions / PropagateDispatcherExceptions on in SamplesApp immediately made two previously-swallowed failures visible, so they are fixed here as well — they are the proof the flags do what they claim:

  • Windows.Globalization.Calendar — FirstYearInThisEra / LastYearInThisEra returned absolute years instead of era-years, which threw once the exception stopped being swallowed (fix(globalization): Express First/LastYearInThisEra as era-years).
  • ItemsViewTests — two tests exercise LinedFlowLayout, which is not implemented in Uno (see [Repeater] Port LinedFlowLayout (new layout) #22909); they previously "passed" on a swallowed exception and are now [Ignore]d like the three sibling LinedFlowLayout tests already in that file.

The unresolved-resource throw is done in the public UpdateResourceBindings method after the defensive InnerUpdateResourceBindings wrapper returns, so no catch (XamlParseException) throw; passthroughs are needed in unrelated swallow sites.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample — Given_FeatureConfiguration_UnhandledExceptions (15 tests covering both flag states for input, dispatcher, and resource lookup, including handled-exception routing, single reporting, theme-switch misses and HighContrast keys served by the global theme).
  • 📚 Docs have been added/updated following the documentation template — the flags are documented inline; happy to add a feature article if reviewers want one.
  • 🖼️ Validated PR Screenshots Compare Test Run results — N/A (no visual changes).
  • ❗ Contains NO breaking changes — all new behavior is gated behind opt-in flags. SamplesApp is the only place defaults are flipped on, and that is intentional for our development loop.
  • 👀 Reviewed 2 other open pull requests

Copilot AI lite review requested due to automatic review settings May 18, 2026 12:05
@github-actions github-actions Bot added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform area/automation Categorizes an issue or PR as relevant to project automation labels May 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds opt-in feature flags to surface previously swallowed input, dispatcher, and unresolved resource errors, aligning Uno behavior more closely with WinUI while keeping defaults unchanged for apps. It also implements real XamlParseException types and enables stricter exception propagation in SamplesApp for development.

Changes:

  • Added input and dispatcher exception propagation flags and wiring across routed events, pointer handling, and native dispatcher paths.
  • Added unresolved resource throwing through ResourceResolution.ThrowOnUnresolvedResource.
  • Added runtime tests and real Microsoft.UI.Xaml.Markup / Windows.UI.Xaml.Markup XamlParseException implementations.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Uno.UI/UI/Xaml/UIElement.RoutedEvents.cs Routes SafeRaiseEvent/SafeRaiseTunnelingEvent exceptions through unhandled exception handling when enabled.
src/Uno.UI/UI/Xaml/UIElement.Pointers.UIKit.cs Applies input exception propagation to UIKit touch handlers.
src/Uno.UI/UI/Xaml/UIElement.Pointers.cs Applies input exception propagation to pointer event raising.
src/Uno.UI/UI/Xaml/Internal/InputManager.Pointers.Managed.cs Propagates top-level managed pointer failures after recovery when enabled.
src/Uno.UI/UI/Xaml/DependencyObjectStore.Theming.cs Detects unresolved resource bindings and throws XamlParseException when configured.
src/Uno.UI/UI/Xaml/Application.cs Adds fatal unhandled exception raising that preserves stack traces.
src/Uno.UI/FeatureConfiguration.cs Adds public opt-in flags for input, dispatcher, and resource resolution behavior.
src/Uno.UI/Extensions/ApplicationExtensions.cs Adds helper to raise or rethrow unhandled exceptions when no app is available.
src/Uno.UI.RuntimeTests/Tests/Uno_UI/Given_FeatureConfiguration_UnhandledExceptions.cs Adds runtime coverage for flag-off/on input behavior, dispatcher swallow behavior, and unresolved resources.
src/Uno.UI.Dispatching/Native/NativeDispatcher.cs Adds dispatcher exception propagation flag and bypasses catch/log path when enabled.
src/Uno.UI.Dispatching/Native/NativeDispatcher.Android.cs Applies dispatcher exception propagation to Android choreographer animation dispatch.
src/Uno.Foundation/Windows.UI.Xaml.Markup/XamlParseException.cs Adds real Windows namespace XamlParseException constructors.
src/Uno.Foundation/Microsoft.UI.Xaml.Markup/XamlParseException.cs Adds real Microsoft namespace XamlParseException constructors.
src/Uno.Foundation/Generated/2.0.0.0/Windows.UI.Xaml.Markup/XamlParseException.cs Updates generated partial to skip manually implemented constructors.
src/Uno.Foundation/Generated/2.0.0.0/Microsoft.UI.Xaml.Markup/XamlParseException.cs Updates generated partial to skip manually implemented constructors.
src/SamplesApp/SamplesApp.Shared/App.xaml.cs Enables input and dispatcher exception propagation in SamplesApp development builds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MartinZikmund MartinZikmund changed the title feat: Opt-in surfacing of input, dispatcher, and resource-lookup errors (closes #19197) feat: Opt-in surfacing of input, dispatcher, and resource-lookup errors May 18, 2026
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/inputswallow branch from 222c032 to debbec4 Compare May 25, 2026 09:56
Copilot AI review requested due to automatic review settings May 25, 2026 10:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings May 25, 2026 12:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.

Comment thread src/Uno.UI/FeatureConfiguration.cs Resolved
Comment thread src/Uno.UWP/Globalization/Calendar.cs Resolved
@MartinZikmund
MartinZikmund force-pushed the dev/mazi/inputswallow branch from dcd5eb6 to f14a80e Compare June 17, 2026 07:44
@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 6m 44s —— View job


PR Review

  • Set up todo list
  • Read changed files
  • Review FeatureConfiguration.cs
  • Review Application.cs and ApplicationExtensions.cs
  • Review NativeDispatcher changes
  • Review UIElement routing changes
  • Review DependencyObjectStore.Theming.cs
  • Review XamlParseException files
  • Review runtime tests
  • Review SamplesApp changes
  • Post inline review comments
  • Write summary

Summary

The feature design is solid: opt-in flags with sane defaults, clean Application.RaiseUnhandledException / RaiseUnhandledExceptionOrThrow plumbing, and well-structured tests. However there are 3 high-severity correctness issues in the dispatcher changes that should be fixed before merge.

High (correctness / must-fix)

# File Issue
1 InputManager.Pointers.Managed.cs:14 Duplicate using Uno.Extensions; — CS0105 warning, the pre-existing line at the bottom already covers it
2 NativeDispatcher.cs:148 _currentPriority not reset in finally — if PropagateDispatcherExceptions = true and the platform catches+continues after the exception, the dispatcher's priority stays stale
3 NativeDispatcher.Android.cs:83 QueueOperations() skipped when exception propagates — remaining _animationQueue items are permanently stranded because no next frame callback is posted

Medium (design / needs decision)

# File Issue
4 DependencyObjectStore.Theming.cs:448 ThrowOnUnresolvedResource fires for all updateReason values, not just load-time. A {ThemeResource} binding that only fails Phase 2's non-theme-aware walk (but resolves fine in Phase 1) can produce a false positive. The flag should either be scoped to ResolvedOnLoading only, or the XML doc should call this out explicitly.
5 DependencyObjectStore.Theming.cs:472 <remarks> placed before <summary> in both InnerUpdateResourceBindings and InnerUpdateResourceBindingsUnsafe — IDE tooling expects <summary> first

Low (housekeeping)

# File Issue
6 Calendar.cs:435 Era-year fix is a separate, unrelated bug fix that isn't mentioned in the PR description — worth splitting or at least describing
7 ItemsViewTests.cs:710 Unconditional [Ignore] hides the test on all platforms; prefer [PlatformCondition] or include a tracking issue reference in the ignore message

What looks good:

  • Application.RaiseUnhandledException / ExceptionDispatchInfo.Capture(e).Throw() correctly preserves the original stack trace, matching WinUI's behavior.
  • The SamplesApp #if __SKIA__ scoping for the flags is correct per the PR description's intent (Skia-first development surface).
  • XamlParseException promotion from [NotImplemented] stubs is clean — the generated file correctly uses the #if false pattern to suppress duplicated generated constructors.
  • Runtime tests cover all three flag states and the handled-vs-unhandled split for input exceptions. The deliberate omission of an automated test for PropagateDispatcherExceptions = true (comment explaining it terminates the host) is the right call.
  • Calendar.cs fix itself is correct and well-commented.

Comment thread src/Uno.UWP/Globalization/Calendar.cs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

WinAppSDK sync generator drift detected on f14a80e

The Uno.WinAppSDKSyncGenerator produced changes that are not committed on this PR.

To apply automatically (PRs from branches in this repo only): comment /apply-sync-gen on this PR and a bot will push chore: Sync generator run to the head branch.

To apply manually (required for PRs from forks):

  1. Download the sync-generator-patch artifact from this run.
  2. In your local checkout of the PR branch:
    git apply sync-generator.patch
    git add -A
    git commit -m "chore: Sync generator run"
    git push
    

Or re-run the generator locally on Windows via build\run-api-sync-tool.cmd.

@github-actions

github-actions Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 6m 31s —— View job


PR Review

  • Set up todo list
  • Read changed files
  • Review FeatureConfiguration.cs
  • Review Application.cs and ApplicationExtensions.cs
  • Review NativeDispatcher changes
  • Review UIElement routing changes
  • Review DependencyObjectStore.Theming.cs
  • Review XamlParseException files
  • Review runtime tests
  • Review SamplesApp changes
  • Post inline review comments
  • Write summary

Summary

The overall design is sound: opt-in flags with sane defaults, clean Application.RaiseUnhandledException / ExceptionDispatchInfo.Capture plumbing, and correct XamlParseException promotion. The latest commit (393aa6c7) fixed the duplicate using Uno.Extensions; from the previous review.

2 high-severity correctness issues remain open in the dispatcher changes:

# File Issue
1 NativeDispatcher.cs:148 _currentPriority not reset in a finally — when PropagateUnhandledExceptions = true and action() throws, the reset that follows RunAction(@this, action) in DispatchItems is never reached, corrupting subsequent dispatch priority
2 NativeDispatcher.Android.cs:83,117 QueueOperations() at the end of DispatchItemsToChoreographer is permanently skipped when the exception propagates — remaining _animationQueue items are stranded with no next Choreographer frame callback posted

1 medium documentation issue:

# File Issue
3 FeatureConfiguration.cs:1228 ThrowOnUnresolvedResource remarks say "Recommended for development and CI" without warning that {ThemeResource} bindings produce widespread false positives (confirmed by the detailed explanation in App.xaml.cs)

1 low / style issue:

# File Issue
4 DependencyObjectStore.Theming.cs:472 <remarks> placed before <summary> on both InnerUpdateResourceBindings and InnerUpdateResourceBindingsUnsafe — IDE tooling expects <summary> first

What looks good:

  • Application.RaiseUnhandledException uses ExceptionDispatchInfo.Capture(e).Throw() to preserve the original stack trace — correct WinUI-parity behavior.
  • The RaiseUnhandledExceptionOrThrow extension method correctly handles Application.Current == null with a log + rethrow fallback.
  • XamlParseException promotion is clean: the generated #if false pattern suppresses duplicate constructors without editing the generated file.
  • The #if __SKIA__ guard in SamplesApp is correct per Skia-first development scope.
  • Runtime tests cover all three flag states and the handled/unhandled split for input; the deliberate omission of a PropagateDispatcherExceptions = true automated test (with an explanatory comment) is the right call.
  • InnerUpdateResourceBindingsUnsafe returns true for bindings whose UpdateReason doesn't match, correctly avoiding false ThrowOnUnresolvedResource fires for unrelated update passes.

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 15s —— View job


PR Review

Verdict: ship. I found no new issues. This was a code-inspection review only. I did not build or run tests, and the clone has no merge base with origin/master, so I read the current head files directly instead of diffing.

Earlier open items, checked against the current head:

  • Duplicate Application.UnhandledException report: fixed. Application.cs marks a reported exception in Exception.Data (UnhandledExceptionReportedKey) and skips it if already marked. The no-Application fallback in RaiseUnhandledExceptionOrThrow uses the same marker. A rethrown exception reaching OnTopLevelFatalError should not be reported a second time. Commit 90cae316 adds a test for a failing injected pointer press reported once.
  • Nullable receiver on ApplicationExtensions: fixed. The file has #nullable enable and both helpers take Application?.
  • Dispatcher priority reset and QueueOperations(): fixed earlier in try/finally blocks.
  • XML doc order and the {ThemeResource} caveat: fixed earlier.

Still open, not blocking:

  • ThrowOnUnresolvedResource still lists a repeated key once per binding. De-duplicating and capping the exception message was suggested by Copilot and is optional.
  • Gating ThrowOnUnresolvedResource to load-time update reasons is still a deferred design call, covered for now by the Known limitation note on the flag.
  • The #if false || false ... lines in the generated XamlParseException files come from the sync generator, so don't edit them by hand.
  • CodeQL flags the generic catch (Exception) in InvokeAppHandlerReportingErrors. It is intentional, because the exception is reported and then rethrown or marked handled.

@MartinZikmund

Copy link
Copy Markdown
Member Author

🤖 Addressed PR comments up to this point

@morning4coffe-dev, on your changes-requested review:

  • Double UnhandledException for one input failure: fixed. An exception left unhandled is now marked as reported (a8b8f78), so the outer InputManager catch doesn't raise it again. 90cae31 tests this with a real injected mouse press through InputManager. Without the guard it reports twice, and with it once.
  • ThrowOnUnresolvedResource false positives: no longer worth a caveat in the docs. The flag now behaves like WinUI's resource-not-found handling, which I confirmed in a WinAppSDK 2.5.1 test app:
    • A {ThemeResource} that never resolves throws XamlParseException once the element is loaded.
    • A miss on a theme switch throws COMException 0x800F1000 after checking the global theme resources.
    • With the flag on across the full Skia runtime suite (~12.4k tests), no failures came from false positives. The misses that did show up came from a test helper that swaps out the Fluent resources, which now turns the flag off for its scope.

Review threads: 23 replied and resolved. The Application? receivers are fixed in 177d90c; the other threads got explanations.

@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from github-actions Bot Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from nventive-devops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@unoplatform unoplatform deleted a comment from unodevops Nov 20, 2026
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248028 found UI Test snapshots differences: skia-linux-screenshots: 232, skia-windows-screenshots: 277

Details
  • skia-linux-screenshots: 232 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • Accessibility_Showcase.png
    • Accessibility_Showcase.png-dark
    • AnimatedBackVisualSourceSamplePage.png
    • AnimatedVisualsTestbedPage.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
  • skia-windows-screenshots: 277 changed over 2500

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedVisualsTestbedPage.png
    • AutomationPropertiesExtensions_Role.png-dark
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • AnimatedVisualsTestbedPage.png-dark
    • AutomationPropertiesExtensions_Role.png
    • AutomationProperties_AutomationId.png-dark
    • BasicAcrylicBrushTest2.png-dark
    • BasicAcrylicBrushTest2.png
    • AutomationProperties_StructureAndProps.png-dark
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • Accessibility_Showcase.png-dark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not swallow exceptions on pointer input and dispatcher

5 participants