Skip to content

Conversation

mydea
Copy link
Member

@mydea mydea commented Sep 17, 2025

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!

@mydea mydea requested a review from onurtemizkan September 17, 2025 07:55
@mydea mydea self-assigned this Sep 17, 2025
cursor[bot]

This comment was marked as outdated.

Comment on lines 107 to 108
captureRemixServerException(err, 'HandleDocumentRequestFunction', request);
},

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 for errorHandleDocumentRequestFunction no longer re-throws the caught error. This violates the contract of the handleCallbackErrors utility, which is designed to always propagate exceptions after executing the callback. By removing throw 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 the onError 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.

Copy link
Member Author

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.

@mydea
Copy link
Member Author

mydea commented Sep 17, 2025

@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...?

@onurtemizkan
Copy link
Collaborator

we could possibly also just remove this wrapping and let this bubble up anyhow?

I agree 👍 The function name is not important or actionable by the end user

@mydea mydea changed the title fix(remix): Actually capture exceptions for HandleDocumentRequestFunction fix(remix): Fix error capture for HandleDocumentRequestFunction Sep 17, 2025
@mydea
Copy link
Member Author

mydea commented Sep 17, 2025

we could possibly also just remove this wrapping and let this bubble up anyhow?

I agree 👍 The function name is not important or actionable by the end user

nice, then I adjust this PR to just drop this handler!

@mydea mydea changed the title fix(remix): Fix error capture for HandleDocumentRequestFunction ref(remix): Avoid unnecessary error wrapping HandleDocumentRequestFunction Sep 17, 2025
cursor[bot]

This comment was marked as outdated.

@mydea mydea merged commit 3410a08 into develop Sep 17, 2025
322 of 325 checks passed
@mydea mydea deleted the fn/remix-fix-capture branch September 17, 2025 12:37
mydea added a commit that referenced this pull request Sep 17, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants