Skip to content

[Settings] Stop fail-fast in ShellViewModel.Frame_NavigationFailed#48409

Open
crutkas wants to merge 1 commit into
microsoft:mainfrom
crutkas:user/crutkas/fix-settings-shell-navigationfailed-nre
Open

[Settings] Stop fail-fast in ShellViewModel.Frame_NavigationFailed#48409
crutkas wants to merge 1 commit into
microsoft:mainfrom
crutkas:user/crutkas/fix-settings-shell-navigationfailed-nre

Conversation

@crutkas

@crutkas crutkas commented Jun 9, 2026

Copy link
Copy Markdown
Member

Summary

ShellViewModel.Frame_NavigationFailed unconditionally re-threw e.Exception. When the WinUI Frame raises NavigationFailed, throwing back from the handler propagates through the WinRT marshalling layer as a stowed exception and the runtime tears the process down via RoFailFastWithErrorContextInternal2 - Settings crashes instead of surfacing a recoverable error.

e.Exception can also be null in some failure paths (e.g., the requested page type cannot be resolved), in which case the previous code immediately raised a NullReferenceException on the throw statement itself.

This was spotted while reading through ShellViewModel for an unrelated review.

Fix

  • Set e.Handled = true so WinUI does not fail-fast.
  • Use Logger.LogError(...) (the existing house pattern via ManagedCommon) to record the navigation failure with the source page name and exception, so it still shows up in PowerToys logs for diagnosis.
  • Tolerate a null SourcePageType by extracting GetPageDisplayName and falling back to "<unknown>".
  • Tolerate a null Exception by calling the LogError(string) overload in that case.

Tests

Added ShellViewModelTests under Settings.UI.UnitTests covering both branches of GetPageDisplayName:

  • known Type -> returns FullName
  • null -> returns <unknown> (no NRE)

Both pass locally (dotnet test ... --filter ShellViewModelTests).

Validation

  • MSBuild PowerToys.Settings.csproj /p:Configuration=Release /p:Platform=x64 builds.
  • MSBuild Settings.UI.UnitTests.csproj builds.
  • Unit tests pass.

Notes

  • The other Frame_NavigationFailed in NavigationService.cs is just NavigationFailed?.Invoke(sender, e); so it does not need changes - the fix is on the actual subscriber.
  • No string-resource changes (the log message is engineering diagnostics, not user-facing UI).

Re-throwing from a NavigationFailed handler propagates back through the WinRT marshalling layer as a stowed exception and FailFasts the Settings process. e.Exception can also be null in some failure paths, immediately yielding a NullReferenceException on the throw itself.

Mark the failure handled, log it via ManagedCommon.Logger, and null-safely format the source page name. Add Settings.UI.UnitTests coverage for the null-safe formatter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Needs-Review This Pull Request awaits the review of a maintainer.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant