CmdPal: Improve crash error message (#43340)

## Summary of the Pull Request

This PR localizes the message displayed when an unhandled exception
causes CmdPal to crash. It also resolves a regression from commit
a991a118dc, which disabled storing to the desktop but failed to
update the corresponding message.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Related to: #41392
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
This commit is contained in:
Jiří Polášek
2025-11-06 18:32:56 +01:00
committed by GitHub
parent 0e922a4dcb
commit 57f0b4b342
2 changed files with 35 additions and 14 deletions

View File

@@ -51,10 +51,10 @@ internal sealed partial class GlobalErrorHandler
// without its exception being observed. It is NOT raised immediately
// when the Task faults; timing depends on GC finalization.
e.SetObserved();
HandleException(e.Exception, Context.UnobservedTaskException, isRecoverable: true);
HandleException(e.Exception, Context.UnobservedTaskException);
}
private void HandleException(Exception ex, Context context, bool isRecoverable = false)
private static void HandleException(Exception ex, Context context)
{
Logger.LogError($"Unhandled exception detected ({context})", ex);
@@ -70,10 +70,25 @@ internal sealed partial class GlobalErrorHandler
StoreReport(report, storeOnDesktop: false);
string message;
string caption;
try
{
message = ResourceLoaderInstance.GetString("GlobalErrorHandler_CrashMessageBox_Message");
caption = ResourceLoaderInstance.GetString("GlobalErrorHandler_CrashMessageBox_Caption");
}
catch
{
// The resource loader may not be available if the exception occurred during startup.
// Fall back to hardcoded strings in that case.
message = "Command Palette has encountered a fatal error and must close.";
caption = "Command Palette - Fatal error";
}
PInvoke.MessageBox(
HWND.Null,
"Command Palette has encountered a fatal error and must close.\n\nAn error report has been saved to your desktop.",
"Unhandled Error",
message,
caption,
MESSAGEBOX_STYLE.MB_ICONERROR);
}
}

View File

@@ -431,8 +431,8 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Run_Radio_Position_LastPosition.Content" xml:space="preserve">
<value>Last Position</value>
<comment>Reopen the window where it was last closed</comment>
</data>
<data name="TrayMenu_Settings" xml:space="preserve">
</data>
<data name="TrayMenu_Settings" xml:space="preserve">
<value>Settings</value>
</data>
<data name="TrayMenu_Close" xml:space="preserve">
@@ -493,28 +493,34 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="Settings_ExtensionsPage_Reloading_Text.Text" xml:space="preserve">
<value>Reloading extensions..</value>
</data>
<data name="Settings_ExtensionsPage_Banner_Header.Text" xml:space="preserve">
<data name="Settings_ExtensionsPage_Banner_Header.Text" xml:space="preserve">
<value>Discover more extensions</value>
</data>
<data name="Settings_ExtensionsPage_Banner_Description.Text" xml:space="preserve">
<data name="Settings_ExtensionsPage_Banner_Description.Text" xml:space="preserve">
<value>Find more extensions on the Microsoft Store or WinGet.</value>
</data>
<data name="Settings_ExtensionsPage_Banner_Hyperlink.Content" xml:space="preserve">
<data name="Settings_ExtensionsPage_Banner_Hyperlink.Content" xml:space="preserve">
<value>Learn how to create your own extensions</value>
</data>
<data name="Settings_ExtensionsPage_FindExtensions_MicrosoftStore.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<data name="Settings_ExtensionsPage_FindExtensions_MicrosoftStore.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Find extensions on the Microsoft Store</value>
</data>
<data name="Settings_ExtensionsPage_FindExtensions_MicrosoftStore.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<data name="Settings_ExtensionsPage_FindExtensions_MicrosoftStore.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Microsoft Store</value>
</data>
<data name="Settings_ExtensionsPage_FindExtensions_WinGet.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<data name="Settings_ExtensionsPage_FindExtensions_WinGet.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
<value>Find extensions on WinGet</value>
</data>
<data name="Settings_ExtensionsPage_FindExtensions_WinGet.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<data name="Settings_ExtensionsPage_FindExtensions_WinGet.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Microsoft Store</value>
</data>
<data name="Settings_ExtensionsPage_SearchBox_Placeholder.PlaceholderText" xml:space="preserve">
<data name="Settings_ExtensionsPage_SearchBox_Placeholder.PlaceholderText" xml:space="preserve">
<value>Search extensions</value>
</data>
<data name="GlobalErrorHandler_CrashMessageBox_Message" xml:space="preserve">
<value>Command Palette has encountered a fatal error and must close.</value>
</data>
<data name="GlobalErrorHandler_CrashMessageBox_Caption" xml:space="preserve">
<value>Command Palette - Fatal error</value>
</data>
</root>