fix: convert Go runtime panics to goja GoError exceptions#23
Merged
Conversation
…unction bridge Go runtime panics (e.g. nil-pointer dereference, index out of range) from native functions bypass JS try/catch blocks because goja's exceptionFromValue only recognises its own types — raw Go panics fall through to a default case that re-panics, skipping the JS catch handler entirely. This adds a deferred recover in the wrappedFn closure that bridges Go native functions to JS. It catches Go runtime panics and re-panics with a GoError exception that goja can route through its try/catch mechanism. Goja-compatible panic values (goja.Value, *goja.Exception) are re-thrown unchanged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TristanSpeakEasy
approved these changes
Mar 4, 2026
Add PanicError type that carries both the Go stack trace (from the panic site) and the JS call stack (from the goja VM), so downstream consumers can extract full context via errors.As. Co-Authored-By: Claude Opus 4.6 <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.
Summary
try/catchblocksexceptionFromValueonly recognises its own types — raw Go panics fell through to adefaultcase that re-panickedrecoverin thewrappedFnclosure (the Go→JS native function bridge) that converts Go runtime panics toGoErrorexceptionsThis fixes an intermittent CI failure in openapi-generation where Ruby SDK generation crashed with:
The Ruby template already had
try/catcharound the offending call, but the Go panic bypassed it.✻ Clauded...