Skip to content

Commit 563bcd8

Browse files
committed
test(node) : add integration test for SuppressedError
1 parent 806ccdf commit 563bcd8

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

  • dev-packages/node-integration-tests/suites/public-api/captureException/suppressed-error
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
transport: loggingTransport,
8+
});
9+
10+
function createResource() {
11+
return {
12+
[Symbol.dispose]() {
13+
throw new Error('error from dispose');
14+
},
15+
};
16+
}
17+
18+
function run(): void {
19+
using _resource = createResource();
20+
throw new Error('original error');
21+
}
22+
23+
try {
24+
run();
25+
} catch (error) {
26+
Sentry.captureException(error);
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { afterAll, describe, expect, test } from 'vitest';
2+
import { supports } from '../../../../utils';
3+
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
4+
5+
afterAll(() => {
6+
cleanupChildProcesses();
7+
});
8+
9+
describe.runIf(supports({ min: 22 }))('SuppressedError', () => {
10+
test('captures both errors of a SuppressedError as chained exceptions', async () => {
11+
await createRunner(__dirname, 'scenario.ts')
12+
.expect({
13+
event: {
14+
exception: {
15+
values: [
16+
{
17+
type: 'Error',
18+
value: 'original error',
19+
mechanism: { type: 'chained', source: 'suppressed', handled: true, exception_id: 2, parent_id: 0 },
20+
},
21+
{
22+
type: 'Error',
23+
value: 'error from dispose',
24+
mechanism: { type: 'chained', source: 'error', handled: true, exception_id: 1, parent_id: 0 },
25+
},
26+
{
27+
type: 'SuppressedError',
28+
value: expect.stringContaining('suppressed during disposal'),
29+
mechanism: { type: 'generic', handled: true, exception_id: 0 },
30+
},
31+
],
32+
},
33+
},
34+
})
35+
.start()
36+
.completed();
37+
});
38+
});

0 commit comments

Comments
 (0)