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

    • Resolved a panic that could occur when closing or cancelling a Save File dialog on Windows.
  • Documentation

    • Updated the changelog to reflect the bug fix for the Save File dialog issue on Windows.

Copy link
Contributor

coderabbitai bot commented May 16, 2025

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
v3/internal/go-common-file-dialog/cfd/vtblCommonFunc.go Changed error returned for nil shellItem from generic error to ErrorCancelled.
v3/pkg/application/dialogs_windows.go Added explicit error handling after showCfdDialog; improved type safety when sending results.
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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

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

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

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

@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 previously approved these changes 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

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 9, 2025
leaanthony
leaanthony previously approved these changes Jul 9, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 9, 2025
@leaanthony leaanthony disabled auto-merge July 9, 2025 12:40
@leaanthony leaanthony enabled auto-merge (squash) July 9, 2025 12:40
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)

28-30: Capitalize “Windows” and add platform icon for consistency

The changelog convention (see legend above) prefixes Windows-specific fixes with “⊞” and capitalizes the OS name. Keeping this consistent improves scan-ability.

- - 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. See [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a414d51 and 4aceb1f.

📒 Files selected for processing (1)
  • docs/src/content/docs/changelog.mdx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: fbbdev
PR: wailsapp/wails#4100
File: v3/internal/runtime/desktop/@wailsio/runtime/src/dialogs.ts:222-228
Timestamp: 2025-02-25T17:13:05.652Z
Learning: The user has chosen to maintain the function name `Error` in the dialogs module despite it shadowing the global Error constructor. This is a deliberate choice due to documentation generator compatibility concerns, and the risk is mitigated by using `window.Error` when referencing the global constructor and by the strictly type-checked modular nature of the code.
docs/src/content/docs/changelog.mdx (5)
Learnt from: popaprozac
PR: wailsapp/wails#4256
File: v2/internal/frontend/desktop/linux/notifications.go:27-28
Timestamp: 2025-04-29T23:54:07.488Z
Learning: In Wails v2, unlike v3-alpha which has a `ServiceShutdown` method for services, there is no standardized teardown pattern for frontend implementations. When implementing features that require cleanup (like goroutines or resources), add explicit cleanup methods (e.g., `CleanupNotifications()`) that handle resource release, context cancellation, and connection closure.
Learnt from: popaprozac
PR: wailsapp/wails#4256
File: v2/internal/frontend/desktop/linux/notifications.go:27-28
Timestamp: 2025-04-29T23:54:07.488Z
Learning: In Wails v2, unlike v3-alpha which has a `ServiceShutdown` method for services, there is no standardized teardown pattern for frontend implementations. When implementing features that require cleanup (like goroutines or resources), add explicit cleanup methods (e.g., `CleanupNotifications()`) that handle resource release, context cancellation, and connection closure.
Learnt from: popaprozac
PR: wailsapp/wails#4098
File: v3/pkg/services/notifications/notifications_darwin.go:39-46
Timestamp: 2025-03-23T00:41:39.612Z
Learning: For the macOS notifications implementation in Wails, an early panic is used when the bundle identifier check fails rather than returning an error, because the Objective-C code would crash later anyway. The panic provides clear instructions to developers about bundling and signing requirements.
Learnt from: fbbdev
PR: wailsapp/wails#4045
File: v3/internal/generator/render/info.go:28-68
Timestamp: 2025-02-04T23:59:43.956Z
Learning: In the Wails v3 project, internal functions are designed to panic on nil parameters as they represent contract violations, rather than adding defensive nil checks.
Learnt from: popaprozac
PR: wailsapp/wails#4098
File: v3/pkg/services/notifications/notifications_windows.go:91-113
Timestamp: 2025-02-24T06:08:55.645Z
Learning: The JSON quote handling in Windows notifications' activation arguments (v3/pkg/services/notifications/notifications_windows.go) has a known limitation with single-quote collisions that needs to be addressed after initial testing.
🪛 LanguageTool
docs/src/content/docs/changelog.mdx

[grammar] ~29-~29: There might be a mistake here.
Context: ...github.aichem.org//pull/4284) by @hkhere ## v3.0.0-alpha.10 - 2025-07-06 ### Break...

(QB_NEW_EN_OTHER)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (macos-latest, 1.24)

leaanthony
leaanthony previously approved these changes Jul 11, 2025
leaanthony
leaanthony previously approved these changes Jul 15, 2025
leaanthony
leaanthony previously approved these changes Jul 20, 2025
Copy link

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)
v3/UNRELEASED_CHANGELOG.md (1)

24-27: Style: align wording with project changelog guidelines

Use present-tense verb (“Fix”), capitalize “Windows”, and consolidate the sentence to avoid repetition.

- - Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere
+ - Fix panic when closing or cancelling a `SaveFileDialog` on Windows (#4279, #4284) by @hkhere
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 330624e and daecbf7.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
v3/UNRELEASED_CHANGELOG.md

[style] ~26-~26: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ncelling a SaveFileDialog on windows. Fixed in [PR](https://github.com/wailsapp/wai...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Go Tests v3 (windows-latest, 1.24)
  • GitHub Check: Run Go Tests v3 (ubuntu-latest, 1.24)

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 lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files. v3-alpha Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants