Skip to content

Commit cf849ab

Browse files
authored
ref(solid): Add mechanism to error captured by withSentryErrorBoundary (#17607)
Adds a mechanism following the trace origin naming conventions. Decided to go with `handled: true` since AFAICT, users always have to provide a fallback (as opposed to react ErrorBoundary where this is optional) closes #17264
1 parent 8077201 commit cf849ab

File tree

10 files changed

+78
-28
lines changed

10 files changed

+78
-28
lines changed

dev-packages/e2e-tests/test-applications/solid-solidrouter/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test('captures an exception', async ({ page }) => {
1515
type: 'ReferenceError',
1616
value: 'NonExistentComponent is not defined',
1717
mechanism: {
18-
type: 'generic',
18+
type: 'auto.function.solid.error_boundary',
1919
handled: true,
2020
},
2121
},
@@ -39,7 +39,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
3939
type: 'ReferenceError',
4040
value: 'NonExistentComponent is not defined',
4141
mechanism: {
42-
type: 'generic',
42+
type: 'auto.function.solid.error_boundary',
4343
handled: true,
4444
},
4545
},
@@ -64,7 +64,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
6464
type: 'ReferenceError',
6565
value: 'NonExistentComponent is not defined',
6666
mechanism: {
67-
type: 'generic',
67+
type: 'auto.function.solid.error_boundary',
6868
handled: true,
6969
},
7070
},

dev-packages/e2e-tests/test-applications/solid/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('captures an exception', async ({ page }) => {
2222
type: 'Error',
2323
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid E2E test app',
2424
mechanism: {
25-
type: 'generic',
25+
type: 'auto.function.solid.error_boundary',
2626
handled: true,
2727
},
2828
},
@@ -53,7 +53,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
5353
type: 'Error',
5454
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid E2E test app',
5555
mechanism: {
56-
type: 'generic',
56+
type: 'auto.function.solid.error_boundary',
5757
handled: true,
5858
},
5959
},
@@ -82,7 +82,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
8282
type: 'Error',
8383
value: 'Error 2 thrown from Sentry ErrorBoundary in Solid E2E test app',
8484
mechanism: {
85-
type: 'generic',
85+
type: 'auto.function.solid.error_boundary',
8686
handled: true,
8787
},
8888
},

dev-packages/e2e-tests/test-applications/solidstart-dynamic-import/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('captures an exception', async ({ page }) => {
2323
type: 'Error',
2424
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
2525
mechanism: {
26-
type: 'generic',
26+
type: 'auto.function.solid.error_boundary',
2727
handled: true,
2828
},
2929
},
@@ -53,7 +53,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
5353
type: 'Error',
5454
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
5555
mechanism: {
56-
type: 'generic',
56+
type: 'auto.function.solid.error_boundary',
5757
handled: true,
5858
},
5959
},
@@ -81,7 +81,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
8181
type: 'Error',
8282
value: 'Error 2 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
8383
mechanism: {
84-
type: 'generic',
84+
type: 'auto.function.solid.error_boundary',
8585
handled: true,
8686
},
8787
},

dev-packages/e2e-tests/test-applications/solidstart-spa/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('captures an exception', async ({ page }) => {
2121
type: 'Error',
2222
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
2323
mechanism: {
24-
type: 'generic',
24+
type: 'auto.function.solid.error_boundary',
2525
handled: true,
2626
},
2727
},
@@ -51,7 +51,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
5151
type: 'Error',
5252
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
5353
mechanism: {
54-
type: 'generic',
54+
type: 'auto.function.solid.error_boundary',
5555
handled: true,
5656
},
5757
},
@@ -79,7 +79,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
7979
type: 'Error',
8080
value: 'Error 2 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
8181
mechanism: {
82-
type: 'generic',
82+
type: 'auto.function.solid.error_boundary',
8383
handled: true,
8484
},
8585
},

dev-packages/e2e-tests/test-applications/solidstart-top-level-import/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('captures an exception', async ({ page }) => {
2121
type: 'Error',
2222
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
2323
mechanism: {
24-
type: 'generic',
24+
type: 'auto.function.solid.error_boundary',
2525
handled: true,
2626
},
2727
},
@@ -51,7 +51,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
5151
type: 'Error',
5252
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
5353
mechanism: {
54-
type: 'generic',
54+
type: 'auto.function.solid.error_boundary',
5555
handled: true,
5656
},
5757
},
@@ -79,7 +79,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
7979
type: 'Error',
8080
value: 'Error 2 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
8181
mechanism: {
82-
type: 'generic',
82+
type: 'auto.function.solid.error_boundary',
8383
handled: true,
8484
},
8585
},

dev-packages/e2e-tests/test-applications/solidstart/tests/errorboundary.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('captures an exception', async ({ page }) => {
2121
type: 'Error',
2222
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
2323
mechanism: {
24-
type: 'generic',
24+
type: 'auto.function.solid.error_boundary',
2525
handled: true,
2626
},
2727
},
@@ -51,7 +51,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
5151
type: 'Error',
5252
value: 'Error 1 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
5353
mechanism: {
54-
type: 'generic',
54+
type: 'auto.function.solid.error_boundary',
5555
handled: true,
5656
},
5757
},
@@ -79,7 +79,7 @@ test('captures a second exception after resetting the boundary', async ({ page }
7979
type: 'Error',
8080
value: 'Error 2 thrown from Sentry ErrorBoundary in Solid Start E2E test app',
8181
mechanism: {
82-
type: 'generic',
82+
type: 'auto.function.solid.error_boundary',
8383
handled: true,
8484
},
8585
},

packages/solid/src/errorboundary.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export function withSentryErrorBoundary(ErrorBoundary: Component<ErrorBoundaryPr
1717
const [local, others] = splitProps(props, ['fallback']);
1818

1919
const fallback = (error: unknown, reset: () => void): JSX.Element => {
20-
captureException(error);
20+
captureException(error, {
21+
mechanism: {
22+
handled: true, // handled because user has to provide a fallback
23+
type: 'auto.function.solid.error_boundary',
24+
},
25+
});
2126

2227
const f = local.fallback;
2328
return typeof f === 'function' ? f(error, reset) : f;

packages/solid/test/errorboundary.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ describe('withSentryErrorBoundary', () => {
4949
));
5050

5151
expect(mockCaptureException).toHaveBeenCalledTimes(1);
52-
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'));
52+
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'), {
53+
mechanism: {
54+
handled: true,
55+
type: 'auto.function.solid.error_boundary',
56+
},
57+
});
5358
});
5459

5560
it('renders the fallback component', async () => {
@@ -89,13 +94,23 @@ describe('withSentryErrorBoundary', () => {
8994
));
9095

9196
expect(mockCaptureException).toHaveBeenCalledTimes(1);
92-
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'));
97+
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'), {
98+
mechanism: {
99+
handled: true,
100+
type: 'auto.function.solid.error_boundary',
101+
},
102+
});
93103

94104
const button = await findByRole('button');
95105
await user.click(button);
96106

97107
expect(mockCaptureException).toHaveBeenCalledTimes(2);
98-
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'));
108+
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'), {
109+
mechanism: {
110+
handled: true,
111+
type: 'auto.function.solid.error_boundary',
112+
},
113+
});
99114
});
100115

101116
it('renders children when there is no error', async () => {

packages/solidstart/test/client/errorboundary.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ describe('withSentryErrorBoundary', () => {
4949
));
5050

5151
expect(mockCaptureException).toHaveBeenCalledTimes(1);
52-
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'));
52+
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'), {
53+
mechanism: {
54+
handled: true,
55+
type: 'auto.function.solid.error_boundary',
56+
},
57+
});
5358
});
5459

5560
it('renders the fallback component', async () => {
@@ -89,13 +94,23 @@ describe('withSentryErrorBoundary', () => {
8994
));
9095

9196
expect(mockCaptureException).toHaveBeenCalledTimes(1);
92-
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'));
97+
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'), {
98+
mechanism: {
99+
handled: true,
100+
type: 'auto.function.solid.error_boundary',
101+
},
102+
});
93103

94104
const button = await findByRole('button');
95105
await user.click(button);
96106

97107
expect(mockCaptureException).toHaveBeenCalledTimes(2);
98-
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'));
108+
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'), {
109+
mechanism: {
110+
handled: true,
111+
type: 'auto.function.solid.error_boundary',
112+
},
113+
});
99114
});
100115

101116
it('renders children when there is no error', async () => {

packages/solidstart/test/server/errorboundary.test.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ describe('withSentryErrorBoundary', () => {
4949
));
5050

5151
expect(mockCaptureException).toHaveBeenCalledTimes(1);
52-
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'));
52+
expect(mockCaptureException).toHaveBeenLastCalledWith(new ReferenceError('NonExistentComponent is not defined'), {
53+
mechanism: {
54+
handled: true,
55+
type: 'auto.function.solid.error_boundary',
56+
},
57+
});
5358
});
5459

5560
it('renders the fallback component', async () => {
@@ -89,13 +94,23 @@ describe('withSentryErrorBoundary', () => {
8994
));
9095

9196
expect(mockCaptureException).toHaveBeenCalledTimes(1);
92-
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'));
97+
expect(mockCaptureException).toHaveBeenNthCalledWith(1, new ReferenceError('NonExistentComponent is not defined'), {
98+
mechanism: {
99+
handled: true,
100+
type: 'auto.function.solid.error_boundary',
101+
},
102+
});
93103

94104
const button = await findByRole('button');
95105
await user.click(button);
96106

97107
expect(mockCaptureException).toHaveBeenCalledTimes(2);
98-
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'));
108+
expect(mockCaptureException).toHaveBeenNthCalledWith(2, new ReferenceError('NonExistentComponent is not defined'), {
109+
mechanism: {
110+
handled: true,
111+
type: 'auto.function.solid.error_boundary',
112+
},
113+
});
99114
});
100115

101116
it('renders children when there is no error', async () => {

0 commit comments

Comments
 (0)