[PR #19504] Fix crash when canceling file picker in profile settings #31860

Open
opened 2026-01-31 09:49:59 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19504

State: closed
Merged: No


Wraps SetClientGuid, SetFileTypes, and related dialog setup calls in try-catch blocks to prevent unhandled exceptions when the user cancels the file selection dialog or when dialog configuration fails.

Previously, if these operations threw an exception (which could happen during cancellation or in certain system states), it would crash the terminal. Now these operations are treated as non-fatal, allowing the dialog to still open even if some configuration steps fail.

Fixes #19501

Fix crash when canceling file picker in profile settings

Summary

Fixes a crash that occurs when users cancel the file selection dialog while setting the Command Line executable or Starting Directory for a profile.

References

Closes #19501

Detailed Description

When adding a new profile and clicking the browse button to select a Command Line executable or Starting Directory, canceling the file dialog would cause the terminal to crash. This happened because some of the file dialog configuration calls could throw exceptions that weren't being caught.

Changes Made

Added proper exception handling to the Commandline_Click and StartingDirectory_Click functions:

  • Wrapped SetClientGuid, SetFileTypes, and related calls in try-catch blocks
  • All caught exceptions are logged but treated as non-fatal
  • This matches the existing pattern used for SetDefaultFolder elsewhere in the codebase

Validation

  • Reproduced the original crash by canceling the file dialog
  • Verified the fix prevents the crash
  • Confirmed the file picker still works correctly when a file is selected

PR Checklist

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19504 **State:** closed **Merged:** No --- Wraps SetClientGuid, SetFileTypes, and related dialog setup calls in try-catch blocks to prevent unhandled exceptions when the user cancels the file selection dialog or when dialog configuration fails. Previously, if these operations threw an exception (which could happen during cancellation or in certain system states), it would crash the terminal. Now these operations are treated as non-fatal, allowing the dialog to still open even if some configuration steps fail. Fixes #19501 Fix crash when canceling file picker in profile settings ## Summary Fixes a crash that occurs when users cancel the file selection dialog while setting the Command Line executable or Starting Directory for a profile. ## References Closes #19501 ## Detailed Description When adding a new profile and clicking the browse button to select a Command Line executable or Starting Directory, canceling the file dialog would cause the terminal to crash. This happened because some of the file dialog configuration calls could throw exceptions that weren't being caught. ### Changes Made Added proper exception handling to the `Commandline_Click` and `StartingDirectory_Click` functions: - Wrapped `SetClientGuid`, `SetFileTypes`, and related calls in try-catch blocks - All caught exceptions are logged but treated as non-fatal - This matches the existing pattern used for `SetDefaultFolder` elsewhere in the codebase ## Validation - Reproduced the original crash by canceling the file dialog - Verified the fix prevents the crash - Confirmed the file picker still works correctly when a file is selected ## PR Checklist - [ X] Closes #19501 - [ x] Tests added/passed - [ x] Documentation updated - If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx - [ x] Schema updated (if necessary)
claunia added the pull-request label 2026-01-31 09:49:59 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31860