Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: v3-alpha
Choose a base branch
from

Conversation

hkhere
Copy link
Contributor

@hkhere hkhere commented May 16, 2025

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.

  • 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.

  • 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:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • 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.

Copy link
Contributor

coderabbitai bot commented May 16, 2025

Walkthrough

The changes introduce improved error handling for the Windows SaveFileDialog, specifically addressing cases where the dialog is cancelled or closed. The modifications ensure that errors are correctly propagated and handled, preventing application crashes. Documentation is updated to reflect the fix for the panic issue when cancelling the dialog.

Changes

File(s) Change Summary
v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go Changed error returned when shellItem is nil from a generic error to ErrorCancelled.
v3/pkg/application/dialogs_windows.go Added explicit error handling after dialog cancellation; type assertion added before channel send.
docs/src/content/docs/changelog.mdx Updated changelog to document the fix for SaveFileDialog panic on Windows.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant SaveFileDialog
    participant OS

    User->>Application: Initiate SaveFileDialog
    Application->>SaveFileDialog: show()
    SaveFileDialog->>OS: showCfdDialog()
    OS-->>SaveFileDialog: Return result or error
    alt Error or Cancelled
        SaveFileDialog->>Application: Return closed channel, error
    else Success
        SaveFileDialog->>Application: Send result (string) on channel
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent catastrophic failure (panic) when SaveFileDialog is cancelled or closed (#4279)
Ensure error or empty string is returned on dialog cancel/close instead of crashing (#4279)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

  • wailsapp/wails#4156: Improves error handling in Windows file dialogs to prevent deadlocks or panics.
  • wailsapp/wails#4253: Refines error signaling in getResultString for dialog cancellation, directly related to SaveFileDialog behavior.
  • wailsapp/wails#3707: Involves related improvements to error handling in internal dialog code, specifically in vtblCommonFunc.go.

Poem

A dialog box once caused a fright,
When cancelled, it crashed out of sight.
But now with a patch,
No more app will dispatch—
Calm bunnies rejoice, all is right!
🐰✨


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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

@github-actions github-actions bot added the Documentation Improvements or additions to documentation label May 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
website/src/pages/changelog.mdx (1)

19-19: Good documentation of the fix in the changelog.

The changelog entry clearly describes the issue that was fixed and references the PR number. This helps users and developers understand what was addressed in this release.

Note: "Windows" should be capitalized as it refers to the operating system.

- Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284)
+ Fixed panic when closing or cancelling a `SaveFileDialog` on Windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284)
🧰 Tools
🪛 LanguageTool

[grammar] ~19-~19: “Windows” (operating system by Microsoft) is a proper noun and needs to be capitalized.
Context: ...ing or cancelling a SaveFileDialog on windows. Fixed in [PR](https://github.com/wails...

(A_WINDOWS)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3716aca and 8c0444b.

📒 Files selected for processing (3)
  • v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go (2 hunks)
  • v3/pkg/application/dialogs_windows.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
website/src/pages/changelog.mdx

[grammar] ~19-~19: “Windows” (operating system by Microsoft) is a proper noun and needs to be capitalized.
Context: ...ing or cancelling a SaveFileDialog on windows. Fixed in [PR](https://github.com/wails...

(A_WINDOWS)

🔇 Additional comments (3)
v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go (1)

171-173: Improved error handling with specific error type.

This change enhances error handling by returning a specific ErrorCancelled error rather than a generic error message. This is a better practice as it allows calling code to check for specific error types rather than parsing error strings.

v3/pkg/application/dialogs_windows.go (2)

199-202: Fixed potential resource leak by properly handling errors.

This is a critical fix that properly handles errors from showCfdDialog by closing the channel and returning early. Previously, an error could have resulted in a resource leak or incorrect behavior because the channel wouldn't be properly closed.


205-208: Added type safety to prevent panic on invalid type assertion.

This change adds proper type assertion with a check, preventing a potential panic if the result is not of the expected type. This is good defensive programming that makes the code more robust against unexpected scenarios.

@atterpac atterpac mentioned this pull request May 30, 2025
@leaanthony leaanthony enabled auto-merge (squash) May 30, 2025 21:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/src/content/docs/changelog.mdx (1)

131-131: Capitalize “Windows” and align entry style.

The new fix entry currently reads “on windows.” Windows is a proper noun and should be capitalized. Also for consistency with other OS‐specific entries, consider adding the ⊞ badge and using the [#4284] PR reference style:

- - Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere
+ - ⊞ Fixed panic when closing or cancelling a `SaveFileDialog` on Windows. Fixed in [#4284](https://github.com/wailsapp/wails/pull/4284) by @hkhere
🧰 Tools
🪛 LanguageTool

[grammar] ~131-~131: “Windows” (operating system by Microsoft) is a proper noun and needs to be capitalized.
Context: ...ing or cancelling a SaveFileDialog on windows. Fixed in [PR](https://github.com/wails...

(A_WINDOWS)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0444b and a414d51.

📒 Files selected for processing (1)
  • docs/src/content/docs/changelog.mdx (2 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/src/content/docs/changelog.mdx

[grammar] ~131-~131: “Windows” (operating system by Microsoft) is a proper noun and needs to be capitalized.
Context: ...ing or cancelling a SaveFileDialog on windows. Fixed in [PR](https://github.com/wails...

(A_WINDOWS)

Copy link

sonarqubecloud bot commented Jun 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation v3-alpha Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants