Compare commits

..

1 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
12e9ee42ca fix(Settings): handle null Exception in Frame_NavigationFailed to prevent NullReferenceException
When NavigationFailedEventArgs.Exception is null, the original code threw a
NullReferenceException instead of a meaningful error. Use null-coalescing to
throw an InvalidOperationException with context about the failed page.
2026-04-29 17:56:18 +08:00

View File

@@ -9,7 +9,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
@@ -136,18 +135,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
var sourcePage = e.SourcePageType?.FullName ?? "<unknown>";
if (e.Exception is null)
{
Logger.LogWarning($"Navigation to '{sourcePage}' failed without an exception.");
}
else
{
Logger.LogError($"Navigation to '{sourcePage}' failed.", e.Exception);
}
e.Handled = true;
throw e.Exception ?? new InvalidOperationException(
$"Navigation to {e.SourcePageType?.FullName ?? "unknown page"} failed.");
}
private void Frame_Navigated(object sender, NavigationEventArgs e)