Skip to content
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

fix(remix): Use captureRemixServerException inside handleError. #466

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

fix(remix): Use captureRemixServerException inside handleError. (#466)

## 3.14.1

ref(sveltekit): Add log for successful Vite plugin insertion (#465)
Expand Down
30 changes: 30 additions & 0 deletions src/remix/codemods/handle-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,42 @@ export function instrumentHandleError(
) {
return false;
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program
.body[0];

// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
handleErrorFunction.declaration.body.body.unshift(
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],
);

// First parameter is the error
//
// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
handleErrorFunction.declaration.params[0] = implementation.params[0];

// Second parameter is the request inside an object
// Merging the object properties to make sure it includes request
//
// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (handleErrorFunction.declaration.params?.[1]?.properties) {
// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
handleErrorFunction.declaration.params[1].properties.push(
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
implementation.params[1].properties[0],
);
} else {
// Create second parameter if it doesn't exist
//
// @ts-expect-error - string works here because the AST is proxified by magicast
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
handleErrorFunction.declaration.params[1] = implementation.params[1];
}
}

return true;
Expand Down
8 changes: 2 additions & 6 deletions src/remix/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {
};
`;

export const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error) {
if (error instanceof Error) {
Sentry.captureRemixErrorBoundaryError(error);
} else {
Sentry.captureException(error);
}
export const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error, { request }) {
Sentry.captureRemixServerException(error, 'remix.server', { request });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onurtemizkan @AbhiPrasad

this won't work;

needs to be:
Sentry.captureRemixServerException(error, 'remix.server', request);

without { } around request

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reporting @wilcoschoneveld! Opened a fix PR. #469

}
`;