fix(fastify): catch thrown route errors - #937
Merged
proggeramlug merged 1 commit intoMay 17, 2026
Merged
Conversation
andrewtdiz
force-pushed
the
codex/issue-928-fastify-error-boundary
branch
from
May 17, 2026 16:42
d217e40 to
41619d5
Compare
andrewtdiz
force-pushed
the
codex/issue-928-fastify-error-boundary
branch
from
May 17, 2026 16:57
41619d5 to
7d39911
Compare
5 tasks
proggeramlug
added a commit
that referenced
this pull request
May 17, 2026
…-in Error layout (#939) stringify_value and stringify_value_depth dispatched GC_TYPE_ERROR through the catch-all -> is_object_pointer -> stringify_object path, which derefed ErrorHeader::error_kind as a keys_array pointer and crashed the process. Add an explicit GC_TYPE_ERROR arm in both that emits "{}" — matches Node's JSON.stringify(new Error("x")) behavior (Error's intrinsic props are non-enumerable per spec). Closes the js_json_stringify fallback hole in the Fastify rejection-body renderer that PR #937 added the catch path for.
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
Closes #928.
try/setjmptraps around native Fastify route handlers,onRequest/preHandlerhooks, and customsetErrorHandlercallbacks in bothperry-ext-fastifyand the in-tree stdlib Fastify implementation.js_throwexit the process when no try frame is active.Errorvalues throughjs_error_get_messageso default 500 bodies are stable and do not use generic JSON stringify onErrorHeader.Root Cause
Async flag propagation was not the primary issue: async arrows/functions already reject their returned Promise for top-level throws. The native Fastify bridge was missing the framework error boundary. It invoked raw Perry closures from Rust without an active
js_try_pushframe, so sync throws from handlers, hooks, or nested helpers reachedjs_throwwithTRY_DEPTH == 0and terminated the process.Verification
cargo fmt --checkcargo check -p perry-stdlib -p perry-ext-fastifycargo build --release -p perry -p perry-runtime -p perry-stdlib -p perry-ext-fastifyPERRY_BIN="$PWD/target/release/perry" scripts/run_fastify_tests.sh—fastify-tests: 10 passed, 0 failedcargo test --release -p perry-ext-fastify— 10 passedcargo test --release -p perry-stdlib fastify— 22 passedContributor Metadata
Per
CONTRIBUTING.md, this PR does not bump[workspace.package],CLAUDE.md, orCHANGELOG.md; release metadata is left for the maintainer at merge time.