Surface dlerror/GetLastError reason on Loader load failure#843
Open
danlniel wants to merge 1 commit into
Open
Conversation
When the Darwin/Linux/Windows loaders fail to dlopen sourcekitdInProc (or libsourcekitdInProc.so / sourcekitdInProc.dll), they currently discard the underlying error and trap with the bare message "Loading X failed". That message tells the user nothing actionable, and the failure has many possible root causes (toolchain not found, architecture mismatch when running through Rosetta, permission, etc). Capture each candidate path that was tried and the OS-reported reason (dlerror() on POSIX, GetLastError() on Windows), and include the full list in the fatalError message. The successful-load path is unchanged. This is the kind of failure SwiftLint users have been hitting on Xcode 26+ when a SwiftLint build phase ends up running through an x86_64 build chain (e.g. an x86_64 ruby / fastlane host) while Xcode 26 ships sourcekitdInProc.framework as arm64-only. Today they get the bare "Loading X failed" trap; after this change they'd see "mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')" pointing straight at the cause. Refs realm/SwiftLint#6475
Collaborator
|
Thanks for the PR - looks good. I think it's OK to not go any further to decode the windows error given the state of support there. |
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.
Summary
Today, when
Loader.load(path:)cannot dlopensourcekitdInProcit traps with the bare messageLoading <path> failed. That message discards the actual OS error and forces downstream users (SwiftLint, jazzy, sourcekitten itself) to guess at the root cause. Users hitting this — e.g. realm/SwiftLint#6475 — end up chasing red herrings (sandboxing, Xcode versions, mise pinning) before the actual cause is found.This PR collects
dlerror()(POSIX) /GetLastError()(Windows) for every candidate path attempted, and includes them in the fatalError message. Successful-load paths are unchanged.Why it matters
The motivating case is Xcode 26 shipping
sourcekitdInProc.frameworkas arm64-only. When SwiftLint is invoked from an x86_64-rooted process tree (e.g. an x86_64 Ruby running fastlane on an Apple Silicon machine), the universal SwiftLint binary launches x86_64 to match its parent, and dlopen fails with:Before this PR users see
Loading sourcekitdInProc.framework/Versions/A/sourcekitdInProc failedand have no idea what to do. After this PR they see the actual reason and can immediately rebuild Ruby as arm64 (or run througharch -arm64) instead.Changes
Loader.loadcollects per-attempt errors and feeds them into a newLoader.failureMessage(path:attemptFailures:)helper.staticso it can be tested without triggeringfatalError.LoaderTestscovers both the populated-attempts path and the empty-attempts edge case.CHANGELOG.mdentry under a new## Mainsection.Test plan
swift build— cleanswift test --filter LoaderTests— 2/2 passswift test— no new failures (6 pre-existingSourceKitTestsfailures are Swift-toolchain-version drift on Xcode 26.4, unrelated to this change)Refs realm/SwiftLint#6475