-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
3.29.0
Plugin version
No response
Node.js version
16.15.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
12.3.1
Description
When I set an error handler on a Fastify instance after registering a plugin within an awaited statement, the error handler does not work as expected.
An example scenario: Let f be a Fastify instance.
- Add a
/get handler on instancefthat throws an error. - Register a plugin on instance
fwith any prefix (e.g.,/bar) with anawaitkeyword. - Set error handler (call it
h) on instancef.
When fetching / on this instance, an error is thrown and h is expected to run. However, it does not. The default handler is run instead.
Removing the await keyword fixes this issue. But the existence of the await keyword or the nonexistence thereof should not alter any behavior--unless there is an intricacy in this situation that forces such behavior.
Steps to Reproduce
A reproduction of the issue can be found here:
https://github.com/omothm/fastify-error-handler-await-repro
Expected Behavior
All 3 test scenarios in the reproduction repo are expected to pass. Currently, one scenario fails (the one with await instance.register()) but was expected to pass.