ref(node)!: Remove deprecated fastify exports, deprecate setupFastifyErrorHandler - #23460
ref(node)!: Remove deprecated fastify exports, deprecate setupFastifyErrorHandler#23460mydea wants to merge 9 commits into
setupFastifyErrorHandler#23460Conversation
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d9cdd33. Configure here.
3004b8c to
3a04de5
Compare
| fastify.addHook('onError', async (request, reply, error) => { | ||
| handleFastifyError(error, request, reply); | ||
| }); |
There was a problem hiding this comment.
Bug: Primitive errors thrown in Fastify v5 route handlers are captured twice because the deduplication logic in checkOrSetAlreadyCaught fails for non-object types.
Severity: LOW
Suggested Fix
Wrap primitive errors in a new Error object within the handleFastifyError function before they are passed to checkOrSetAlreadyCaught and captureException. This will allow the __sentry_captured__ property to be set correctly, ensuring the error is only captured once.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/server-utils/src/integrations/fastify/instrumentation.ts#L409-L411
Potential issue: In Fastify v5, when a primitive value like a string or number is thrown
in a route handler, it gets captured and sent to Sentry twice. This occurs because two
separate error handling paths, the `tracing:fastify.request.handler:error` diagnostics
channel and the `onError` hook, both attempt to report the error. The deduplication
mechanism, `checkOrSetAlreadyCaught`, is designed to prevent this by setting a
`__sentry_captured__` property on the error. However, this function cannot set
properties on primitive values, causing the deduplication to fail silently and both
paths to report the same error.

This removes deprecated/unneeded fastify exports.
It also deprecates
setupFastifyErrorHandler- it is no longer needed. instead, you can fully configure the error handler for all versions of fastify now via the integration.I also removed the override tests from e2e tests, instead testing that you can still override the error handler in a node-integration-test.