@sentry/wizard 3.25.0 → 3.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.25.1
4
+
5
+ - fix(remix): Change `handleError` in server entry (#621)
6
+
3
7
  ## 3.25.0
4
8
 
5
9
  - feat(react-native): Add support for Expo projects (#505)
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.25.0",
3
+ "version": "3.25.1",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -39,13 +39,21 @@ var magicast_1 = require("magicast");
39
39
  function instrumentHandleError(originalEntryServerMod, serverEntryFilename) {
40
40
  var _a, _b;
41
41
  var originalEntryServerModAST = originalEntryServerMod.$ast;
42
- var handleErrorFunction = originalEntryServerModAST.body.find(function (node) {
42
+ var handleErrorFunctionExport = originalEntryServerModAST.body.find(function (node) {
43
43
  var _a, _b;
44
- return node.type === 'ExportNamedDeclaration' &&
44
+ return (node.type === 'ExportNamedDeclaration' &&
45
45
  ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) === 'FunctionDeclaration' &&
46
- ((_b = node.declaration.id) === null || _b === void 0 ? void 0 : _b.name) === 'handleError';
46
+ ((_b = node.declaration.id) === null || _b === void 0 ? void 0 : _b.name) === 'handleError');
47
+ });
48
+ var handleErrorFunctionVariableDeclarationExport = originalEntryServerModAST.body.find(function (node) {
49
+ var _a;
50
+ return node.type === 'ExportNamedDeclaration' &&
51
+ ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) === 'VariableDeclaration' &&
52
+ // @ts-expect-error - id should always have a name in this case
53
+ node.declaration.declarations[0].id.name === 'handleError';
47
54
  });
48
- if (!handleErrorFunction) {
55
+ if (!handleErrorFunctionExport &&
56
+ !handleErrorFunctionVariableDeclarationExport) {
49
57
  prompts_1.default.log.warn("Could not find function ".concat(chalk_1.default.cyan('handleError'), " in ").concat(chalk_1.default.cyan(serverEntryFilename), ". Creating one for you."));
50
58
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
51
59
  var implementation = recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program
@@ -55,42 +63,36 @@ function instrumentHandleError(originalEntryServerMod, serverEntryFilename) {
55
63
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
56
64
  recast.types.builders.exportNamedDeclaration(implementation));
57
65
  }
58
- else if ((0, utils_1.hasSentryContent)((0, magicast_1.generateCode)(handleErrorFunction).code, originalEntryServerMod.$code, 'captureRemixServerException')) {
66
+ else if ((handleErrorFunctionExport &&
67
+ ['wrapHandleErrorWithSentry', 'sentryHandleError'].some(function (util) {
68
+ return (0, utils_1.hasSentryContent)((0, magicast_1.generateCode)(handleErrorFunctionExport).code, originalEntryServerMod.$code, util);
69
+ })) ||
70
+ (handleErrorFunctionVariableDeclarationExport &&
71
+ ['wrapHandleErrorWithSentry', 'sentryHandleError'].some(function (util) {
72
+ return (0, utils_1.hasSentryContent)((0, magicast_1.generateCode)(handleErrorFunctionVariableDeclarationExport).code, originalEntryServerMod.$code, util);
73
+ }))) {
59
74
  return false;
60
75
  }
61
- else {
76
+ else if (handleErrorFunctionExport) {
62
77
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
63
78
  var implementation = recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program
64
79
  .body[0];
65
- // @ts-expect-error - string works here because the AST is proxified by magicast
80
+ // If the current handleError function has a body, we need to merge the new implementation with the existing one
66
81
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
67
- handleErrorFunction.declaration.body.body.unshift(
68
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
69
- recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0]);
70
- // First parameter is the error
71
- //
72
- // @ts-expect-error - string works here because the AST is proxified by magicast
73
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
- handleErrorFunction.declaration.params[0] = implementation.params[0];
75
- // Second parameter is the request inside an object
76
- // Merging the object properties to make sure it includes request
77
- //
78
- // @ts-expect-error - string works here because the AST is proxified by magicast
82
+ (_a = implementation.declarations[0].init.arguments[0].body.body).unshift.apply(_a, handleErrorFunctionExport.declaration.body.body);
83
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
84
+ handleErrorFunctionExport.declaration = implementation;
85
+ }
86
+ else if (handleErrorFunctionVariableDeclarationExport) {
79
87
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
80
- if ((_b = (_a = handleErrorFunction.declaration.params) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.properties) {
81
- // @ts-expect-error - string works here because the AST is proxified by magicast
82
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
83
- handleErrorFunction.declaration.params[1].properties.push(
84
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
85
- implementation.params[1].properties[0]);
86
- }
87
- else {
88
- // Create second parameter if it doesn't exist
89
- //
90
- // @ts-expect-error - string works here because the AST is proxified by magicast
91
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
92
- handleErrorFunction.declaration.params[1] = implementation.params[1];
93
- }
88
+ var implementation = recast.parse(templates_1.HANDLE_ERROR_TEMPLATE_V2).program
89
+ .body[0];
90
+ // If the current handleError function has a body, we need to merge the new implementation with the existing one
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
92
+ (_b = implementation.declarations[0].init.arguments[0].body.body).unshift.apply(_b, handleErrorFunctionVariableDeclarationExport.declaration
93
+ .declarations[0].init.body.body);
94
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
95
+ handleErrorFunctionVariableDeclarationExport.declaration = implementation;
94
96
  }
95
97
  return true;
96
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../../../../src/remix/codemods/handle-error.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM5D,6CAAiC;AAEjC,0CAAwD;AACxD,kCAA2E;AAE3E,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAwC;AAExC,SAAgB,qBAAqB,CACnC,sBAA4C,EAC5C,mBAA2B;;IAE3B,IAAM,yBAAyB,GAAG,sBAAsB,CAAC,IAAe,CAAC;IAEzE,IAAM,mBAAmB,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAC7D,UAAC,IAAI;;QACH,OAAA,IAAI,CAAC,IAAI,KAAK,wBAAwB;YACtC,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,qBAAqB;YAChD,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,EAAE,0CAAE,IAAI,MAAK,aAAa,CAAA;KAAA,CAC9C,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE;QACxB,iBAAK,CAAC,GAAG,CAAC,IAAI,CACZ,kCAA2B,eAAK,CAAC,IAAI,CAAC,aAAa,CAAC,iBAAO,eAAK,CAAC,IAAI,CACnE,mBAAmB,CACpB,4BAAyB,CAC3B,CAAC;QAEF,sEAAsE;QACtE,IAAM,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,oCAAwB,CAAC,CAAC,OAAO;aAClE,IAAI,CAAC,CAAC,CAAC,CAAC;QAEX,yBAAyB,CAAC,IAAI,CAAC,MAAM,CACnC,IAAA,qCAA6B,EAAC,yBAAyB,CAAC,EACxD,CAAC;QACD,gFAAgF;QAChF,iEAAiE;QACjE,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAC7D,CAAC;KACH;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CAAC;SACtE;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AA/ED,sDA+EC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\nimport type { Program } from '@babel/types';\n\nimport * as recast from 'recast';\n\nimport { HANDLE_ERROR_TEMPLATE_V2 } from '../templates';\nimport { getAfterImportsInsertionIndex, hasSentryContent } from '../utils';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode } from 'magicast';\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n serverEntryFilename: string,\n): boolean {\n const originalEntryServerModAST = originalEntryServerMod.$ast as Program;\n\n const handleErrorFunction = originalEntryServerModAST.body.find(\n (node) =>\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError',\n );\n\n if (!handleErrorFunction) {\n clack.log.warn(\n `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(\n serverEntryFilename,\n )}. Creating one for you.`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n hasSentryContent(\n generateCode(handleErrorFunction).code,\n originalEntryServerMod.$code,\n 'captureRemixServerException',\n )\n ) {\n return false;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.body.body.unshift(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],\n );\n\n // First parameter is the error\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n handleErrorFunction.declaration.params[0] = implementation.params[0];\n\n // Second parameter is the request inside an object\n // Merging the object properties to make sure it includes request\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (handleErrorFunction.declaration.params?.[1]?.properties) {\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n handleErrorFunction.declaration.params[1].properties.push(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n implementation.params[1].properties[0],\n );\n } else {\n // Create second parameter if it doesn't exist\n //\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n handleErrorFunction.declaration.params[1] = implementation.params[1];\n }\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"handle-error.js","sourceRoot":"","sources":["../../../../src/remix/codemods/handle-error.ts"],"names":[],"mappings":";AAAA,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM5D,6CAAiC;AAEjC,0CAAwD;AACxD,kCAA2E;AAE3E,+EAA+E;AAC/E,2DAAmC;AACnC,gDAA0B;AAE1B,kFAAkF;AAClF,qCAAwC;AAExC,SAAgB,qBAAqB,CACnC,sBAA4C,EAC5C,mBAA2B;;IAE3B,IAAM,yBAAyB,GAAG,sBAAsB,CAAC,IAAe,CAAC;IAEzE,IAAM,yBAAyB,GAAG,yBAAyB,CAAC,IAAI,CAAC,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CAAC,IAAI,EACjC;QAEF,qFAAqF;QACrF,4CAA4C,CAAC,WAAW,GAAG,cAAc,CAAC;KAC3E;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAnGD,sDAmGC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\nimport type { Program } from '@babel/types';\n\nimport * as recast from 'recast';\n\nimport { HANDLE_ERROR_TEMPLATE_V2 } from '../templates';\nimport { getAfterImportsInsertionIndex, hasSentryContent } from '../utils';\n\n// @ts-expect-error - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\nimport chalk from 'chalk';\n\n// @ts-expect-error - magicast is ESM and TS complains about that. It works though\nimport { generateCode } from 'magicast';\n\nexport function instrumentHandleError(\n originalEntryServerMod: ProxifiedModule<any>,\n serverEntryFilename: string,\n): boolean {\n const originalEntryServerModAST = originalEntryServerMod.$ast as Program;\n\n const handleErrorFunctionExport = originalEntryServerModAST.body.find(\n (node) => {\n return (\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'FunctionDeclaration' &&\n node.declaration.id?.name === 'handleError'\n );\n },\n );\n\n const handleErrorFunctionVariableDeclarationExport =\n originalEntryServerModAST.body.find(\n (node) =>\n node.type === 'ExportNamedDeclaration' &&\n node.declaration?.type === 'VariableDeclaration' &&\n // @ts-expect-error - id should always have a name in this case\n node.declaration.declarations[0].id.name === 'handleError',\n );\n\n if (\n !handleErrorFunctionExport &&\n !handleErrorFunctionVariableDeclarationExport\n ) {\n clack.log.warn(\n `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(\n serverEntryFilename,\n )}. Creating one for you.`,\n );\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n originalEntryServerModAST.body.splice(\n getAfterImportsInsertionIndex(originalEntryServerModAST),\n 0,\n // @ts-expect-error - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n recast.types.builders.exportNamedDeclaration(implementation),\n );\n } else if (\n (handleErrorFunctionExport &&\n ['wrapHandleErrorWithSentry', 'sentryHandleError'].some((util) =>\n hasSentryContent(\n generateCode(handleErrorFunctionExport).code,\n originalEntryServerMod.$code,\n util,\n ),\n )) ||\n (handleErrorFunctionVariableDeclarationExport &&\n ['wrapHandleErrorWithSentry', 'sentryHandleError'].some((util) =>\n hasSentryContent(\n generateCode(handleErrorFunctionVariableDeclarationExport).code,\n originalEntryServerMod.$code,\n util,\n ),\n ))\n ) {\n return false;\n } else if (handleErrorFunctionExport) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n // If the current handleError function has a body, we need to merge the new implementation with the existing one\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n implementation.declarations[0].init.arguments[0].body.body.unshift(\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ...handleErrorFunctionExport.declaration.body.body,\n );\n\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n handleErrorFunctionExport.declaration = implementation;\n } else if (handleErrorFunctionVariableDeclarationExport) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program\n .body[0];\n\n // If the current handleError function has a body, we need to merge the new implementation with the existing one\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n implementation.declarations[0].init.arguments[0].body.body.unshift(\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ...handleErrorFunctionVariableDeclarationExport.declaration\n .declarations[0].init.body.body,\n );\n\n // @ts-expect-error - declaration works here because the AST is proxified by magicast\n handleErrorFunctionVariableDeclarationExport.declaration = implementation;\n }\n\n return true;\n}\n"]}
@@ -1,2 +1,2 @@
1
1
  export declare const ERROR_BOUNDARY_TEMPLATE_V2 = "const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n";
2
- export declare const HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request, true);\n}\n";
2
+ export declare const HANDLE_ERROR_TEMPLATE_V2 = "const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {\n // Custom handleError implementation\n});\n";
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HANDLE_ERROR_TEMPLATE_V2 = exports.ERROR_BOUNDARY_TEMPLATE_V2 = void 0;
4
4
  exports.ERROR_BOUNDARY_TEMPLATE_V2 = "const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n";
5
- exports.HANDLE_ERROR_TEMPLATE_V2 = "function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request, true);\n}\n";
5
+ exports.HANDLE_ERROR_TEMPLATE_V2 = "const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {\n // Custom handleError implementation\n});\n";
6
6
  //# sourceMappingURL=templates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,4JAKzC,CAAC;AAEW,QAAA,wBAAwB,GAAG,8HAGvC,CAAC","sourcesContent":["export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n`;\n\nexport const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error, { request }) {\n Sentry.captureRemixServerException(error, 'remix.server', request, true);\n}\n`;\n"]}
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../src/remix/templates.ts"],"names":[],"mappings":";;;AAAa,QAAA,0BAA0B,GAAG,4JAKzC,CAAC;AAEW,QAAA,wBAAwB,GAAG,+HAGvC,CAAC","sourcesContent":["export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {\n const error = useRouteError();\n captureRemixErrorBoundaryError(error);\n return <div>Something went wrong</div>;\n};\n`;\n\nexport const HANDLE_ERROR_TEMPLATE_V2 = `const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {\n // Custom handleError implementation\n});\n`;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/wizard",
3
- "version": "3.25.0",
3
+ "version": "3.25.1",
4
4
  "homepage": "https://github.com/getsentry/sentry-wizard",
5
5
  "repository": "https://github.com/getsentry/sentry-wizard",
6
6
  "description": "Sentry wizard helping you to configure your project",
@@ -22,14 +22,29 @@ export function instrumentHandleError(
22
22
  ): boolean {
23
23
  const originalEntryServerModAST = originalEntryServerMod.$ast as Program;
24
24
 
25
- const handleErrorFunction = originalEntryServerModAST.body.find(
26
- (node) =>
27
- node.type === 'ExportNamedDeclaration' &&
28
- node.declaration?.type === 'FunctionDeclaration' &&
29
- node.declaration.id?.name === 'handleError',
25
+ const handleErrorFunctionExport = originalEntryServerModAST.body.find(
26
+ (node) => {
27
+ return (
28
+ node.type === 'ExportNamedDeclaration' &&
29
+ node.declaration?.type === 'FunctionDeclaration' &&
30
+ node.declaration.id?.name === 'handleError'
31
+ );
32
+ },
30
33
  );
31
34
 
32
- if (!handleErrorFunction) {
35
+ const handleErrorFunctionVariableDeclarationExport =
36
+ originalEntryServerModAST.body.find(
37
+ (node) =>
38
+ node.type === 'ExportNamedDeclaration' &&
39
+ node.declaration?.type === 'VariableDeclaration' &&
40
+ // @ts-expect-error - id should always have a name in this case
41
+ node.declaration.declarations[0].id.name === 'handleError',
42
+ );
43
+
44
+ if (
45
+ !handleErrorFunctionExport &&
46
+ !handleErrorFunctionVariableDeclarationExport
47
+ ) {
33
48
  clack.log.warn(
34
49
  `Could not find function ${chalk.cyan('handleError')} in ${chalk.cyan(
35
50
  serverEntryFilename,
@@ -48,50 +63,55 @@ export function instrumentHandleError(
48
63
  recast.types.builders.exportNamedDeclaration(implementation),
49
64
  );
50
65
  } else if (
51
- hasSentryContent(
52
- generateCode(handleErrorFunction).code,
53
- originalEntryServerMod.$code,
54
- 'captureRemixServerException',
55
- )
66
+ (handleErrorFunctionExport &&
67
+ ['wrapHandleErrorWithSentry', 'sentryHandleError'].some((util) =>
68
+ hasSentryContent(
69
+ generateCode(handleErrorFunctionExport).code,
70
+ originalEntryServerMod.$code,
71
+ util,
72
+ ),
73
+ )) ||
74
+ (handleErrorFunctionVariableDeclarationExport &&
75
+ ['wrapHandleErrorWithSentry', 'sentryHandleError'].some((util) =>
76
+ hasSentryContent(
77
+ generateCode(handleErrorFunctionVariableDeclarationExport).code,
78
+ originalEntryServerMod.$code,
79
+ util,
80
+ ),
81
+ ))
56
82
  ) {
57
83
  return false;
58
- } else {
84
+ } else if (handleErrorFunctionExport) {
59
85
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
60
86
  const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program
61
87
  .body[0];
62
88
 
63
- // @ts-expect-error - string works here because the AST is proxified by magicast
89
+ // If the current handleError function has a body, we need to merge the new implementation with the existing one
64
90
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
65
- handleErrorFunction.declaration.body.body.unshift(
91
+ implementation.declarations[0].init.arguments[0].body.body.unshift(
92
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
66
93
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
67
- recast.parse(HANDLE_ERROR_TEMPLATE_V2).program.body[0].body.body[0],
94
+ ...handleErrorFunctionExport.declaration.body.body,
68
95
  );
69
96
 
70
- // First parameter is the error
71
- //
72
- // @ts-expect-error - string works here because the AST is proxified by magicast
97
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
98
+ handleErrorFunctionExport.declaration = implementation;
99
+ } else if (handleErrorFunctionVariableDeclarationExport) {
73
100
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
- handleErrorFunction.declaration.params[0] = implementation.params[0];
101
+ const implementation = recast.parse(HANDLE_ERROR_TEMPLATE_V2).program
102
+ .body[0];
75
103
 
76
- // Second parameter is the request inside an object
77
- // Merging the object properties to make sure it includes request
78
- //
79
- // @ts-expect-error - string works here because the AST is proxified by magicast
80
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
81
- if (handleErrorFunction.declaration.params?.[1]?.properties) {
82
- // @ts-expect-error - string works here because the AST is proxified by magicast
83
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
84
- handleErrorFunction.declaration.params[1].properties.push(
85
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
86
- implementation.params[1].properties[0],
87
- );
88
- } else {
89
- // Create second parameter if it doesn't exist
90
- //
91
- // @ts-expect-error - string works here because the AST is proxified by magicast
104
+ // If the current handleError function has a body, we need to merge the new implementation with the existing one
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
106
+ implementation.declarations[0].init.arguments[0].body.body.unshift(
107
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
92
108
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
93
- handleErrorFunction.declaration.params[1] = implementation.params[1];
94
- }
109
+ ...handleErrorFunctionVariableDeclarationExport.declaration
110
+ .declarations[0].init.body.body,
111
+ );
112
+
113
+ // @ts-expect-error - declaration works here because the AST is proxified by magicast
114
+ handleErrorFunctionVariableDeclarationExport.declaration = implementation;
95
115
  }
96
116
 
97
117
  return true;
@@ -5,7 +5,7 @@ export const ERROR_BOUNDARY_TEMPLATE_V2 = `const ErrorBoundary = () => {
5
5
  };
6
6
  `;
7
7
 
8
- export const HANDLE_ERROR_TEMPLATE_V2 = `function handleError(error, { request }) {
9
- Sentry.captureRemixServerException(error, 'remix.server', request, true);
10
- }
8
+ export const HANDLE_ERROR_TEMPLATE_V2 = `const handleError = Sentry.wrapHandleErrorWithSentry((error, { request }) => {
9
+ // Custom handleError implementation
10
+ });
11
11
  `;