-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(remix): Avoid unnecessary error wrapping HandleDocumentRequestFunction
#17680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
packages/remix/src/server/errors.ts
Outdated
captureRemixServerException(err, 'HandleDocumentRequestFunction', request); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential bug: The error callback for HandleDocumentRequestFunction
no longer re-throws errors, swallowing exceptions and breaking the error handling flow for document requests.
-
Description: The
onError
callback forerrorHandleDocumentRequestFunction
no longer re-throws the caught error. This violates the contract of thehandleCallbackErrors
utility, which is designed to always propagate exceptions after executing the callback. By removingthrow err;
, any error occurring during the server-side document rendering process is captured but then swallowed. This prevents Remix's higher-level error handling from triggering, which can lead to clients receiving incomplete or invalid HTML responses instead of a proper error page, while the server continues in an inconsistent state. -
Suggested fix: Restore the original behavior by re-adding
throw err;
at the end of theonError
callback. This ensures that after the exception is captured, it is correctly propagated, allowing Remix's standard error handling mechanisms to generate a proper error response.
severity: 0.85, confidence: 0.98
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this already re-throws out of the box.
@onurtemizkan based on the tests, we could possibly also just remove this wrapping and let this bubble up anyhow? https://github.com/getsentry/sentry-javascript/actions/runs/17790747804/job/50567093382?pr=17680 not sure if we care about the specific function name here...? |
I agree 👍 The function name is not important or actionable by the end user |
HandleDocumentRequestFunction
HandleDocumentRequestFunction
nice, then I adjust this PR to just drop this handler! |
HandleDocumentRequestFunction
HandleDocumentRequestFunction
I've seen a few places where we are wrapping things that could be sync or async, and we want to do something with the return value. By adding an onSuccess handler to `handelCallbackErrors` we can handle this more generically in the future: ```js const wrapped = handleCallbackErrors( () => fn(), // error handler (_err) => {}, // finally handler () => {}, // success handler, gets value or resolved value if function returns a promise (_value) => {} ); ``` While scanning a bit for places where we could already use this, I also found two bugs around this, opened separate PRs for them: * #17680 * #17681
Noticed while working on #17679, this was actually incorrect here.
handleCallbackErrors
does not actually do anything, you need to still call the function you want to call in the error case!Actually we can just drop this as this error is handled by some other handler anyhow, I think, according to the tests!