Skip to content

fix: bundle Highlightr SPM resources — stops launch crash (SIGTRAP) - #1

Merged
johnfkoo951 merged 1 commit into
mainfrom
fix/spm-resource-bundle-crash
Jun 26, 2026
Merged

fix: bundle Highlightr SPM resources — stops launch crash (SIGTRAP)#1
johnfkoo951 merged 1 commit into
mainfrom
fix/spm-resource-bundle-crash

Conversation

@johnfkoo951

Copy link
Copy Markdown
Owner

Problem

Multiple users reported v1.4.6 crashing on launch (EXC_BREAKPOINT / SIGTRAP). The crash report points straight at Highlightr's resource bundle:

0  libswiftCore  _assertionFailure
1  CmdMD         closure #1 in variable initialization expression of static NSBundle.module
5  CmdMD         Highlightr.init(highlightPath:)
6  CmdMD         one-time initialization function for sharedHighlightr
9  CmdMD         SyntaxHighlighter.highlightr(for:)
10 CmdMD         SyntaxHighlighter.highlightCodeBlocks(in:font:theme:)
15 CmdMD         SyntaxHighlighter.applyHighlights(to:font:theme:)
16 CmdMD         MarkdownTextEditor.makeNSView(context:)
...            (during NSPersistentUIRestorer window/session restore)

Root cause — the Swift module wasn't packaged

scripts/package_app.sh copied only the executable into CmdMD.app, never the SwiftPM-generated Highlightr_Highlightr.bundle (highlight.js + the CSS theme files). Highlightr's synthesized Bundle.module accessor traps (it's a fatalError, 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 run masked it locally because the resource bundle sits right next to the dev binary in .build/.

Fix

  • package_app.sh — copy every *.bundle from the release bin dir into Contents/Resources/, so Bundle.module resolves through Bundle.main.resourceURL. (codesign --deep already signs the nested bundle.)
  • SyntaxHighlighter — probe for the resource bundle before instantiating Highlightr; 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 — assert Highlightr_Highlightr.bundle is present in the packaged app. This regression can no longer ship silently (and the release workflow runs this script).
  • Version bump → 1.4.7 (build 13) so users actually receive the fix via the in-app update checker.

Verification

  • bash scripts/test_package_app.shBundling resource: Highlightr_Highlightr.bundle + PASS.
  • Launched the packaged .app in Split mode on a doc containing a Swift code block: highlights correctly, no crash (this is the exact path that crashed before).
  • swift test57 passing.

Release

After merge, tag v1.4.7 to trigger the release workflow (it asserts the tag matches CFBundleShortVersionString, now 1.4.7).

…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
johnfkoo951 merged commit 9967e61 into main Jun 26, 2026
1 check passed
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>
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.

1 participant