Skip to content

Commit f7b4f95

Browse files
committed
fix(node-core): do not print rejection warning in strict mode
This matches the behavior of Node.js.
1 parent d75440c commit f7b4f95

5 files changed

Lines changed: 57 additions & 9 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const Sentry = require('@sentry/node-core');
2+
const { setupOtel } = require('../../../utils/setupOtel.js');
3+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
4+
5+
const client = Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [Sentry.onUnhandledRejectionIntegration({ mode: 'strict' })],
8+
});
9+
10+
setupOtel(client);
11+
12+
expectProcessToExit();
13+
14+
Promise.reject(new Error('test rejection'));

dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,22 @@ Error: test rejection
5151
expect(err).not.toBeNull();
5252
expect(err?.code).toBe(1);
5353
expect(stdout).not.toBe("I'm alive!");
54-
expect(stderr)
55-
.toContain(`This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
56-
test rejection`);
54+
expect(stderr).toBe('test rejection\n');
55+
done();
56+
});
57+
}));
58+
59+
test('should show error-type promise rejections in strict mode', () =>
60+
new Promise<void>(done => {
61+
expect.assertions(4);
62+
63+
const testScriptPath = path.resolve(__dirname, 'mode-strict-error.js');
64+
65+
childProcess.execFile('node', [testScriptPath], { encoding: 'utf8' }, (err, stdout, stderr) => {
66+
expect(err).not.toBeNull();
67+
expect(err?.code).toBe(1);
68+
expect(stdout).not.toBe("I'm alive!");
69+
expect(stderr).toContain('Error: test rejection');
5770
done();
5871
});
5972
}));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const Sentry = require('@sentry/node');
2+
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
integrations: [Sentry.onUnhandledRejectionIntegration({ mode: 'strict' })],
7+
});
8+
9+
expectProcessToExit();
10+
11+
Promise.reject(new Error('test rejection'));

dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,22 @@ Error: test rejection
5252
expect(err).not.toBeNull();
5353
expect(err?.code).toBe(1);
5454
expect(stdout).not.toBe("I'm alive!");
55-
expect(stderr)
56-
.toContain(`This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
57-
test rejection`);
55+
expect(stderr).toBe('test rejection\n');
56+
done();
57+
});
58+
}));
59+
60+
test('should show error-type promise rejections in strict mode', () =>
61+
new Promise<void>(done => {
62+
expect.assertions(4);
63+
64+
const testScriptPath = path.resolve(__dirname, 'mode-strict-error.js');
65+
66+
childProcess.execFile('node', [testScriptPath], { encoding: 'utf8' }, (err, stdout, stderr) => {
67+
expect(err).not.toBeNull();
68+
expect(err?.code).toBe(1);
69+
expect(stdout).not.toBe("I'm alive!");
70+
expect(stderr).toContain('Error: test rejection');
5871
done();
5972
});
6073
}));

packages/node-core/src/integrations/onunhandledrejection.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ function handleRejection(reason: unknown, mode: UnhandledRejectionMode): void {
143143
console.error(reason && typeof reason === 'object' && 'stack' in reason ? reason.stack : reason);
144144
});
145145
} else if (mode === 'strict') {
146-
consoleSandbox(() => {
147-
console.warn(rejectionWarning);
148-
});
149146
logAndExitProcess(reason);
150147
}
151148
/* eslint-enable no-console */

0 commit comments

Comments
 (0)