Harden the Custom Metrics file importer - #72
Open
Kyome22 wants to merge 1 commit into
Open
Conversation
Use the array-based fileImporter overload with allowsMultipleSelection set to false and guard the first URL, so the completion never relies on SwiftUI's single-selection adapter. Move the file importer, the file dialog modifiers and the confirmation dialog off the Section and onto a concrete view, so they are not replicated per row. This mirrors the custom runner importer, which already uses both patterns. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context of Contribution
Summary of the Proposal
Important
This does not fully resolve #47. The root cause of that report is still unidentified, and this PR must not be treated as a fix for it. #47 should stay open until the crash is actually reproduced. See "Relation to #47" below.
Two changes to the Custom Metrics file importer, both aligning it with the custom runner importer that already exists in this codebase.
1. Use the array-based
fileImporteroverload.CustomMetricsSettingsSectionViewusedfileImporter(isPresented:allowedContentTypes:onCompletion:), the single-selection convenience overload. SwiftUI implements it on top of the array-based one: a wrapper closure convertsResult<[URL], Error>intoResult<URL, Error>. Disassembling SwiftUI on macOS 26.5.2 confirms the shape of that adapter and that it reachesbrk #0x1traps from array-count comparisons.This PR calls the array overload directly with
allowsMultipleSelection: falseand guards the first URL, so that adapter is never entered.CustomRunnerEditorViewalready does this.CustomMetricsSettings.Action.onCompletionFileImportertherefore carriesResult<[URL], any Error>instead ofResult<URL, any Error>, matchingCustomRunnerSettings.2. Move the presentation modifiers off the
Section..fileImporter,.fileDialogMessage,.fileDialogConfirmationLabeland.confirmationDialogwere attached to theSectionitself. Modifiers applied to aSectioninside aFormcan be replicated per row, which would bind several importers to the sameshowingFileImporterstate. They now sit on the concreteHStackthat holds the add button, the same wayCustomRunnerSettingsSectionViewattaches its.sheetto a button rather than to the section.No user-visible behaviour changes.
Relation to #47
#47 reports an
EXC_BREAKPOINTwhose top frame is exactly SwiftUI's single-selection adapter, so the overload change addresses the mechanism that report points at. However, the crash could not be reproduced:1.0.3built from source — the exact version named in the reportlldbIn every attempt the import completed successfully.
lldbcaught no trap and no crash report was produced. The reporter has not provided the JSON file that was requested, and the stack trace in the report contains no app frames, thread numbers or exception codes.So the trigger condition remains unknown. This PR removes a class of failure and makes the code consistent, but it is not a verified fix.
Reason for the new feature
N/A — not a new feature.
Checklist
DependencyClient, no logic inUserInterfaceviews, no Asset/String Catalog references fromModel.Verification
xcodebuild build -project RunCatNeo.xcodeproj -scheme RunCatNeo— succeededxcodebuild test -scheme LocalPackage-Package -destination 'platform=macOS,arch=arm64'— 170 tests passed (DataSourceTests 29, ModelTests 141), 0 failuressend_onCompletionFileImporter_success_without_url_is_noop, covering an empty selection🤖 Generated with Claude Code