Skip to content

Surface dlerror/GetLastError reason on Loader load failure#843

Merged
johnfairh merged 1 commit into
jpsim:mainfrom
danlniel:improve-loader-failure-diagnostics
Jun 29, 2026
Merged

Surface dlerror/GetLastError reason on Loader load failure#843
johnfairh merged 1 commit into
jpsim:mainfrom
danlniel:improve-loader-failure-diagnostics

Conversation

@danlniel

Copy link
Copy Markdown
Contributor

Summary

Today, when Loader.load(path:) cannot dlopen sourcekitdInProc it traps with the bare message Loading <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.framework as 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:

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

Before this PR users see Loading sourcekitdInProc.framework/Versions/A/sourcekitdInProc failed and have no idea what to do. After this PR they see the actual reason and can immediately rebuild Ruby as arm64 (or run through arch -arm64) instead.

Changes

  • Loader.load collects per-attempt errors and feeds them into a new Loader.failureMessage(path:attemptFailures:) helper.
  • The helper is static so it can be tested without triggering fatalError.
  • New LoaderTests covers both the populated-attempts path and the empty-attempts edge case.
  • CHANGELOG.md entry under a new ## Main section.

Test plan

  • swift build — clean
  • swift test --filter LoaderTests — 2/2 pass
  • Full swift test — no new failures (6 pre-existing SourceKitTests failures are Swift-toolchain-version drift on Xcode 26.4, unrelated to this change)
  • Manually verified the new message format reads well with real dyld errors

Refs realm/SwiftLint#6475

@johnfairh

Copy link
Copy Markdown
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.

@danlniel danlniel closed this Jun 17, 2026
@johnfairh johnfairh reopened this Jun 20, 2026
@johnfairh

Copy link
Copy Markdown
Collaborator

I do want to take this, just mired in thinking about currency updates, WWDC ...

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.
@johnfairh
johnfairh force-pushed the improve-loader-failure-diagnostics branch from 6239713 to 4882b56 Compare June 29, 2026 09:58
@johnfairh
johnfairh merged commit c642dff into jpsim:main Jun 29, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants