fix: propagate return value from fastify.errorHandler#582
Merged
mcollina merged 1 commit intoMay 18, 2026
Conversation
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.
Fixes #581.
Problem
The wrapper
errorHandlerregistered on the static routes callsfastify.errorHandler(error, request, reply)but discards its returnvalue (
index.js:79).That breaks custom error handlers that rely on Fastify's normal contract
of returning a value (or a Promise) instead of calling
reply.sendthemselves. In particular, an
asyncerror handler that returns itspayload never resolves the reply, because the dropped promise is never
awaited by Fastify.
Vanilla Fastify routes propagate that return value, so this was a
behavioral discrepancy specific to
@fastify/static.Fix
Return the value from
fastify.errorHandler(...)so the application'serror handler can short-circuit / transform the reply exactly like it
would on a non-static route. One-line change.
Tests
Added a focused regression test in
test/static.test.jsthat:asyncsetErrorHandlerreturning its payload (withoutcalling
reply.send).preHandlerso the static route's wrappererrorHandlerruns.error handler reach the client.
Without the fix this test times out (the dropped promise never resolves
the reply). With the fix it passes.
Checks
npm test— 320/320 passing, 100% line coverage retained.npm run lint— clean.