Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Sentry = require('@sentry/node-core');
const { setupOtel } = require('../../../utils/setupOtel.js');
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');

const client = Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.onUnhandledRejectionIntegration({ mode: 'strict' })],
});

setupOtel(client);

expectProcessToExit();

Promise.reject(new Error('test rejection'));
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ test rejection`);
});
}));

test('should not show warning for error-type promise rejections in strict mode', () =>
new Promise<void>(done => {
expect.assertions(5);

const testScriptPath = path.resolve(__dirname, 'mode-strict-error.js');

childProcess.execFile('node', [testScriptPath], { encoding: 'utf8' }, (err, stdout, stderr) => {
expect(err).not.toBeNull();
expect(err?.code).toBe(1);
expect(stdout).not.toBe("I'm alive!");
expect(stderr).toContain('Error: test rejection');
expect(stderr).not.toContain('The promise rejected with the reason');
done();
});
}));

test('should not close process or warn on unhandled rejection in none mode', () =>
new Promise<void>(done => {
expect.assertions(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const Sentry = require('@sentry/node');
const { expectProcessToExit } = require('../../../utils/expect-process-to-exit');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
integrations: [Sentry.onUnhandledRejectionIntegration({ mode: 'strict' })],
});

expectProcessToExit();

Promise.reject(new Error('test rejection'));
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ test rejection`);
});
}));

test('should not show warning for error-type promise rejections in strict mode', () =>
new Promise<void>(done => {
expect.assertions(5);

const testScriptPath = path.resolve(__dirname, 'mode-strict-error.js');

childProcess.execFile('node', [testScriptPath], { encoding: 'utf8' }, (err, stdout, stderr) => {
expect(err).not.toBeNull();
expect(err?.code).toBe(1);
expect(stdout).not.toBe("I'm alive!");
expect(stderr).toContain('Error: test rejection');
expect(stderr).not.toContain('The promise rejected with the reason');
done();
});
}));

test('should not close process or warn on unhandled rejection in none mode', () =>
new Promise<void>(done => {
expect.assertions(3);
Expand Down
8 changes: 5 additions & 3 deletions packages/node-core/src/integrations/onunhandledrejection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ function handleRejection(reason: unknown, mode: UnhandledRejectionMode): void {
console.error(reason && typeof reason === 'object' && 'stack' in reason ? reason.stack : reason);
});
} else if (mode === 'strict') {
consoleSandbox(() => {
Comment thread
mohd-akram marked this conversation as resolved.
console.warn(rejectionWarning);
});
if (!(reason && typeof reason === 'object' && 'stack' in reason)) {
consoleSandbox(() => {
console.warn(rejectionWarning);
});
}
logAndExitProcess(reason);
}
/* eslint-enable no-console */
Expand Down
Loading