fix: bundle Highlightr SPM resources — stops launch crash (SIGTRAP) - #1
Merged
Conversation
…aunch
v1.4.6 crashed on launch (SIGTRAP) for users whenever an editor with a code
block was rendered — including window/session restore:
_assertionFailure → Bundle.module (Highlightr) → Highlightr.init
→ SyntaxHighlighter.highlightr(for:) → highlightCodeBlocks
→ MarkdownTextEditor.makeNSView
Root cause: `scripts/package_app.sh` copied only the executable into the .app,
never the SwiftPM-generated `Highlightr_Highlightr.bundle` (highlight.js + CSS
themes). Highlightr's synthesized `Bundle.module` accessor *traps* (not throws)
when that bundle is absent, so the first code-block highlight took the whole app
down. Local `swift run` masked it because the bundle sits next to the dev binary.
Fixes:
- package_app.sh: copy every `*.bundle` from the release bin dir into
Contents/Resources so `Bundle.module` resolves via `Bundle.main.resourceURL`
(deep codesign already covers the nested bundle).
- SyntaxHighlighter: probe for the resource bundle before instantiating
Highlightr; if it is somehow still missing, log and disable highlighting
instead of trapping — defense in depth against a hard crash.
- test_package_app.sh: assert the Highlightr bundle is present in the packaged
app, so this regression can never ship silently again.
- Bump to 1.4.7 (build 13) so the fix reaches users via the update checker.
Verified: packaged app launches in Split mode on a doc with a Swift code block,
highlights correctly, no crash. 57 tests pass.
johnfkoo951
pushed a commit
that referenced
this pull request
Jun 27, 2026
PR #1 shipped the SPM resource bundle in Contents/Resources, but the swift-build Bundle.module accessor looks at the .app root (unsignable) and a baked .build path (absent on user machines), never Contents/Resources — so source/split editor render still traps with SIGTRAP on 1.4.7. - package_app.sh: repoint the baked fallback path to the shipped Contents/Resources bundle before codesign (scripts/fix-highlightr-bundle.py). - FIX_FOR_CLAUDE_CODE.md: root cause, reproduce, fix options, regression test. Co-Authored-By: Claude Opus 4.8 (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.
Problem
Multiple users reported v1.4.6 crashing on launch (
EXC_BREAKPOINT/ SIGTRAP). The crash report points straight at Highlightr's resource bundle:Root cause — the Swift module wasn't packaged
scripts/package_app.shcopied only the executable intoCmdMD.app, never the SwiftPM-generatedHighlightr_Highlightr.bundle(highlight.js + the CSS theme files). Highlightr's synthesizedBundle.moduleaccessor traps (it's afatalError, not a thrown error) when that bundle can't be found — so the first time an editor with a code block renders (which session-restore does automatically), the whole app goes down.swift runmasked it locally because the resource bundle sits right next to the dev binary in.build/.Fix
package_app.sh— copy every*.bundlefrom the release bin dir intoContents/Resources/, soBundle.moduleresolves throughBundle.main.resourceURL. (codesign --deepalready signs the nested bundle.)SyntaxHighlighter— probe for the resource bundle before instantiatingHighlightr; if it's somehow still missing, log + disable code highlighting instead of trapping. Defense-in-depth so a packaging slip can never hard-crash the app again.test_package_app.sh— assertHighlightr_Highlightr.bundleis present in the packaged app. This regression can no longer ship silently (and the release workflow runs this script).Verification
bash scripts/test_package_app.sh→Bundling resource: Highlightr_Highlightr.bundle+PASS..appin Split mode on a doc containing a Swift code block: highlights correctly, no crash (this is the exact path that crashed before).swift test→ 57 passing.Release
After merge, tag
v1.4.7to trigger the release workflow (it asserts the tag matchesCFBundleShortVersionString, now1.4.7).