[V3] Windows: fix(application): handle error and type assertion in save file dialog
Description
This fixes a failure when closing or cancelling a SaveFileDialog on windows.
Ensure the save file dialog properly handles errors and safely asserts the result type to avoid potential runtime panics. Additionally, improve error handling in the file dialog result retrieval to return a specific error when the operation is cancelled. Fixes #4279
Type of change
Please select the option that is relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.
- [x] Windows
- [ ] macOS
- [ ] Linux
If you checked Linux, please specify the distro and version.
Test Configuration
Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.
Checklist:
- [x] I have updated
website/src/pages/changelog.mdxwith details of this PR - [x] My code follows the general coding style of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
Summary by CodeRabbit
-
Bug Fixes
- Fixed a crash that could occur when closing or cancelling the Save File dialog on Windows.
-
Documentation
- Updated the changelog to include details about the resolved Save File dialog issue on Windows.
Walkthrough
The changes address error handling in the Windows SaveFileDialog implementation. They update error signaling when a dialog is cancelled, ensuring a specific error is returned instead of a generic one. The dialog result handling is made safer to prevent panics on type assertion failures. Documentation is updated to reflect the bug fix.
Changes
| File(s) | Change Summary |
|---|---|
Internal dialog error handlingv3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go |
Changed error returned for nil shellItem from generic error to ErrorCancelled. |
Windows SaveFileDialog improvementsv3/pkg/application/dialogs_windows.go |
Added explicit error handling after showCfdDialog; improved type safety when sending results. |
Changelog updatev3/UNRELEASED_CHANGELOG.md |
Added bug fix entry for SaveFileDialog panic on cancel/close on Windows. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant App
participant SaveFileDialog
participant OS
User->>App: Initiate SaveFileDialog
App->>SaveFileDialog: show()
SaveFileDialog->>OS: Display dialog
OS-->>SaveFileDialog: User selects file or cancels
alt User selects file
SaveFileDialog->>App: Return file path (string)
else User cancels/closes
SaveFileDialog->>App: Return ErrorCancelled
end
App->>User: Process result or report error
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~7 minutes
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Prevent catastrophic failure on cancel/close of SaveFileDialog on Windows (#4279) | ✅ | |
| Return error or empty string instead of panicking when dialog is cancelled or closed (#4279) | ✅ |
Assessment against linked issues: Out-of-scope changes
No out-of-scope changes detected.
Possibly related issues
- #4461: The changes in error handling and type assertion in
windowSaveFileDialog.show()correspond closely to the panic-on-ESC issue described, indicating a strong relation.
Possibly related PRs
- #4253: Similar modification of error handling in
getResultStringmethod ofiFileDialogVtblto return a predefined cancellation error. - #4188: Related improvements to error handling and result processing in
dialogs_windows.goaroundshowCfdDialog. - #4156: Enhancements to error handling for Windows file dialogs to prevent deadlocks or panics during cancellation.
Suggested labels
Bug, v3, size:XS
Poem
A dialog pops, the user may flee—
No more panics for you or for me!
If you cancel or close,
The app simply knows,
And handles it calmly, as safe as can be.
🐇✨
✨ Finishing Touches
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Explain this complex logic.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai explain this code block.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and explain its main purpose.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai generate docstringsto generate docstrings for this PR.@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR.@coderabbitai generate unit teststo generate unit tests for this PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code