wails icon indicating copy to clipboard operation
wails copied to clipboard

[V3] Windows: fix(application): handle error and type assertion in save file dialog

Open hkhere opened this issue 7 months ago • 2 comments

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.mdx with 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.

hkhere avatar May 16 '25 00:05 hkhere

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 handling
v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go
Changed error returned for nil shellItem from generic error to ErrorCancelled.
Windows SaveFileDialog improvements
v3/pkg/application/dialogs_windows.go
Added explicit error handling after showCfdDialog; improved type safety when sending results.
Changelog update
v3/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 getResultString method of iFileDialogVtbl to return a predefined cancellation error.
  • #4188: Related improvements to error handling and result processing in dialogs_windows.go around showCfdDialog.
  • #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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere 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.

coderabbitai[bot] avatar May 16 '25 00:05 coderabbitai[bot]