Skip to content

Fix BclLauncher.Exec throw exception instead of return false - #21704

Merged
MrJul merged 2 commits into
AvaloniaUI:masterfrom
Misaka-L:fix/bcl-launcher-throw-exception-instead-of-return-false
Jul 6, 2026
Merged

MrJul merged 2 commits into
AvaloniaUI:masterfrom
Misaka-L:fix/bcl-launcher-throw-exception-instead-of-return-false

Conversation

@Misaka-L

@Misaka-L Misaka-L commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

This pull request add a try catch block to the Avalonia.Platform.Storage.FileIO.BclLauncher.Exec method.
Which will catch all the exception throw by Process.Start() and return false when it throw.

What is the current behavior?

As #21673 described, if Process.Start() throw a exception, the BclLauncher will throw the exception instead of return false.
(In the case, if user try to launch a url, which url handler path is not exist, it will throw Win32Exception)

Since the API return a bool, developers may pretend this API will return is operation succussed instead of throw a exception.

What is the updated/expected behavior with this PR?

The BclLauncher.Exec should never throw exception, instead, it return false as user may excepted.

How was the solution implemented (if it's not obvious)?

Add a try catch block to the Avalonia.Platform.Storage.FileIO.BclLauncher.Exec method.

*NOTE: It will also hide all exception which maybe helpful for debugging, maybe debug logging or an API (not in this PR) throw exception will be better.

Checklist

  • Added unit tests (if possible)?
  • Added XML documentation to any related classes?
    • It just make BclLauncher behavior match the ILauncher document described.
  • Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation
    • Maybe we should add a warning about the this behavior changed, but i don't have a idea.

Fixed issues

Fixes #21673

@Misaka-L
Misaka-L force-pushed the fix/bcl-launcher-throw-exception-instead-of-return-false branch from bd4abc4 to 5ccd9c9 Compare July 5, 2026 10:18
@Misaka-L
Misaka-L marked this pull request as ready for review July 5, 2026 10:18
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067163-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Jul 5, 2026 •

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@Misaka-L

Misaka-L commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jul 6, 2026
}
}
else
catch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please log the exception (use Logger.TryGet).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

image

Added

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0067215-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 6, 2026
Merged via the queue into AvaloniaUI:master with commit 176b2b8 Jul 6, 2026
11 checks passed
@MrJul MrJul removed the backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BclLauncher.LaunchUriAsync throw exception when launch a url with command` point to a no existing file

4 participants