You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@sentry/remix: Incompatible type in wrapRemixHandleError #10212
error TS2345: Argument of type 'ActionFunctionArgs | LoaderFunctionArgs' is not assignable to parameter of type 'DataFunctionArgs'.
Type 'ActionFunctionArgs' is not assignable to type 'DataFunctionArgs'.
Types of property 'request' are incompatible.
Type 'Request' is not assignable to type 'RemixRequest'.
Type 'Request' is not assignable to type 'Record<string | symbol, RemixRequestState>'.
Index signature for type 'string' is missing in type 'Request'.
(the error is the same if you use the deprecated DataFunctionArgs type from Remix, so it's not just because of the change to use ActionFunctionArgs | LoaderFunctionArgs).
We have exported wrapRemixHandleError for easy instrumentation for non-custom error-handling scenarios.
Should be used like: export const handleError = wrapRemixHandleError;
If you would like to have custom error handling logic inside handleError, I'd recommend using Sentry.captureRemixServerException instead, which wrapRemixHandleError uses in its core:
To use captureRemixServerException directly, I would have to reproduce the logic of wrapRemixHandleError within my handleError implementation to avoid capturing thrown responses twice, and remember to catch the result so that failure doesn't result in an unhandled promise rejection.
Yes, it's doable, but it'd be nicer to just be able to call wrapRemixHandleError (and then I don't have to keep track of any upstream changes made in @sentry/remix that I might need to copy). It doesn't really make sense to me that a function would only be able to be used if exported directly 🤷♂️
This makes sense to me as well. So are we going to replace the current implementation wrapRemixHandleError with the new wrapper, or are we going to keep both (if so we may need to rename one to avoid confusion)?
I would add a new function called wrapHandleErrorWithSentry like I suggested and leave the old one exactly as it is. Naming-wise I recommend we alias wrapRemixHandleError with sentryHandleError, because it is not really wrapping things but instead a full handler. We could deprecate the old name (wrapRemixHandleError).
Activity
Lms24 commentedon Jan 17, 2024
Hi @haines thanks for writing in! We'll take a look.
cc @onurtemizkan when you have time, please
onurtemizkan commentedon Jan 22, 2024
Hi @haines, thanks for reporting.
We have exported
wrapRemixHandleErrorfor easy instrumentation for non-custom error-handling scenarios.Should be used like:
export const handleError = wrapRemixHandleError;If you would like to have custom error handling logic inside
handleError, I'd recommend usingSentry.captureRemixServerExceptioninstead, whichwrapRemixHandleErroruses in its core:sentry-javascript/packages/remix/src/utils/instrumentServer.ts
Lines 91 to 105 in 7e3207d
haines commentedon Jan 22, 2024
Hi @onurtemizkan, thanks for looking at this.
To use
captureRemixServerExceptiondirectly, I would have to reproduce the logic ofwrapRemixHandleErrorwithin myhandleErrorimplementation to avoid capturing thrown responses twice, and remember tocatchthe result so that failure doesn't result in an unhandled promise rejection.Yes, it's doable, but it'd be nicer to just be able to call
wrapRemixHandleError(and then I don't have to keep track of any upstream changes made in@sentry/remixthat I might need to copy). It doesn't really make sense to me that a function would only be able to be used if exported directly 🤷♂️lforst commentedon Jan 25, 2024
@onurtemizkan It would make sense to me that we provided a wrapper for user's
handleErrorfunction. Do we already have that?onurtemizkan commentedon Jan 25, 2024
@lforst, we don't have a wrapper, but we can make this work as @haines mentioned. If we update the typing of the implementation.
We can make this loosely typed to reduce the risk of breaking when Remix changes its internal types.
lforst commentedon Jan 25, 2024
I would argue we should have a wrapper that takes a users implementation of the
handleErrorfunction.The type definition should looks like this:
Similar to how we do it in Next.js:
sentry-javascript/packages/nextjs/src/index.types.ts
Lines 177 to 183 in ef2834d
We then need to do some internal validation of the parameters so that the arguments are what we expect them to be.
onurtemizkan commentedon Jan 25, 2024
This makes sense to me as well. So are we going to replace the current implementation
wrapRemixHandleErrorwith the new wrapper, or are we going to keep both (if so we may need to rename one to avoid confusion)?lforst commentedon Jan 25, 2024
I would add a new function called
wrapHandleErrorWithSentrylike I suggested and leave the old one exactly as it is. Naming-wise I recommend we aliaswrapRemixHandleErrorwithsentryHandleError, because it is not really wrapping things but instead a full handler. We could deprecate the old name (wrapRemixHandleError).onurtemizkan commentedon Jan 25, 2024
Sounds good 👍 I'll try to open a PR later today.
Update manual-setup.mdx
Update manual-setup.mdx (#10393)