Skip to content

fix(v2/darwin): stop file dialogs crashing on unresolvable filters - #6251

Open
somaz94 wants to merge 1 commit into
wailsapp:masterfrom
somaz94:bugfix/5554_dialog-filter-crash
Open

somaz94 wants to merge 1 commit into
wailsapp:masterfrom
somaz94:bugfix/5554_dialog-filter-crash

Conversation

@somaz94

@somaz94 somaz94 commented Oct 12, 2026 •

Copy link
Copy Markdown

Description

On macOS 11 and later the v2 Open and Save dialogs build their filter list with [UTType typeWithFilenameExtension:] and add the result to an array without a nil check. That call returns nil for anything that is not a single plain extension, so a pattern such as *.tar.gz or busted.exe throws NSInvalidArgumentException and the app aborts.

Both dialogs now share one helper. An extension that does not resolve is retried with its last component, so tar.gz filters on gzip and busted.exe on exe, and anything that still does not resolve is skipped. If nothing resolves, the dialog opens without a filter, which is what the save dialog already did for an empty list. UTType cannot express a compound extension or a full file name, so those two cases become a slightly wider filter rather than an exact one.

I did not port the v3 fix from #5678 as is. On macOS 11 and later setAllowedFileTypes: and setAllowedContentTypes: share the same storage, so calling the first after the second drops the types that did resolve. With *.png;*.tar.gz the png filter disappears: a small AppKit check on macOS 14.6 shows allowedContentTypes going from public.png to empty after setAllowedFileTypes:@[@"tar.gz"].

Fixes #5554

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • WEP (proposal only; no implementation)
  • 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?

The darwin package has no Go test harness and cgo cannot be used from a _test.go file, so I tested with a minimal v2 app built once against master and once against this branch. It opens the dialog from OnDomReady with a single filter pattern and reports success if the process is still alive three seconds later.

  • *.png;*.jpg, open and save: the dialog opens on master and on this branch
  • busted;busted.exe, open and save: master aborts with "object cannot be nil", this branch opens the dialog
  • *.tar.gz, open and save: master aborts, this branch opens the dialog
  • *.png;*.tar.gz, open and save: master aborts, this branch opens the dialog

I also compiled the helper into a small harness that prints the resolved types, and *.png;*.tar.gz gives public.png, org.gnu.gnu-zip-archive. go test ./... in v2 passes with Go 1.25.14, and clang -Wall -Wunguarded-availability -mmacosx-version-min=10.13 reports no new warnings for WailsContext.m.

  • Windows
  • macOS
  • Linux

Test Configuration

# Wails
┌───────────────────┐
| Version | v2.16.0 |
└───────────────────┘
# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | MacOS                                                                                                                   |
| Version      | 14.6.1                                                                                                                  |
| ID           | 23G93                                                                                                                   |
| Branding     |                                                                                                                         |
| Go Version   | go1.25.14                                                                                                               |
| Platform     | darwin                                                                                                                  |
| Architecture | arm64                                                                                                                   |
| CPU 1        | Apple M3                                                                                                                |
| CPU 2        | Apple M3                                                                                                                |
| GPU          | Chipset Model: Apple M3 Type: GPU Bus: Built-In Total Number of Cores: 10 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory       | 24GB                                                                                                                    |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
# Dependencies
┌────────────────────────────────────────────────────────────────┐
| Dependency                | Package Name | Status    | Version |
| Xcode command line tools  | N/A          | Installed | 2408    |
| Nodejs                    | N/A          | Installed | 23.11.0 |
| npm                       | N/A          | Installed | 10.9.2  |
| *Xcode                    | N/A          | Available |         |
| *upx                      | N/A          | Available |         |
| *nsis                     | N/A          | Available |         |
|                                                                |
└─────────────────── * - Optional Dependency ────────────────────┘

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • 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 in macOS open and save dialogs when file filters include compound extensions, such as .tar.gz, or unrecognized extensions. Dialogs now handle these filters more reliably, allowing files to be selected without the app crashing.

@github-actions github-actions Bot added Bug Something isn't working v2 labels Oct 12, 2026
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: wailsapp/wails/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3f1cf1d7-3da5-40aa-a89d-67179d6f9320

📥 Commits

Reviewing files that changed from the base of the PR and between acc71e1 and 2f4ba5a.


📒 Files selected for processing (2)
  • v2/internal/frontend/desktop/darwin/WailsContext.m
  • website/src/pages/changelog.mdx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



Walkthrough

macOS file-dialog filters now use a shared helper to convert extensions into recognized content types. Open and save dialogs allow other file types when no content types are recognized. The changelog documents the crash fix.

Changes

macOS dialog filter handling

Layer / File(s) Summary
Convert filters to content types
v2/internal/frontend/desktop/darwin/WailsContext.m
A macOS 11+ helper converts filter extensions to UTType values. If direct conversion fails, it retries with the final path extension and returns only recognized types.
Apply converted filters to dialogs
v2/internal/frontend/desktop/darwin/WailsContext.m, website/src/pages/changelog.mdx
Open and save dialogs use the helper. When no types are recognized, the dialogs allow other file types. The changelog describes the crash fix. The compile-time fallback remains unchanged.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2f4ba

The dialog change is mergeable after normal checks. Unresolvable filters no longer produce nil content types, and broader matching for compound extensions is intentional.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preventing v2 macOS file dialogs from crashing on unresolvable filters.
Description check Passed The description is complete and relevant. It explains the cause, implementation, issue reference, testing results, macOS test configuration, and changelog update. The automated test checklist item and…
Linked Issues check Passed The directly linked issue is #5554. The reviewed head updates v2/internal/frontend/desktop/darwin/WailsContext.m with one shared filter-conversion helper for the macOS open and save dialogs. The hel…
Out of Scope Changes check Passed The reviewed changes are limited to macOS dialog filter handling in v2/internal/frontend/desktop/darwin/WailsContext.m and a related Unreleased entry in website/src/pages/changelog.mdx. The shared…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

I’m a rabbit with filters to try,
I sort UTTypes as they hop by.
If none make the list,
Other file types persist.
Open and save dialogs won’t crash by!

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation MacOS labels Oct 12, 2026
somaz94 added a commit to somaz94/somaz94 that referenced this pull request Oct 12, 2026
@somaz94
somaz94 marked this pull request as ready for review October 12, 2026 07:55
@somaz94

somaz94 commented Oct 12, 2026

Copy link
Copy Markdown
Author

Testing on macOS 14.6 is done, with the results in the description, so this is ready for review. The PR checks are waiting for workflow approval.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation MacOS v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenFileDialog crash on macOS 15.7.3

1 participant