diff --git a/packages/node-integration-tests/suites/public-api/OnUncaughtException/log-entire-error-to-console.js b/packages/node-integration-tests/suites/public-api/OnUncaughtException/log-entire-error-to-console.js new file mode 100644 index 000000000000..758f9e26cc5b --- /dev/null +++ b/packages/node-integration-tests/suites/public-api/OnUncaughtException/log-entire-error-to-console.js @@ -0,0 +1,7 @@ +const Sentry = require('@sentry/node'); + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', +}); + +throw new Error('foo', { cause: 'bar' }); diff --git a/packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts b/packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts index 00c8459466c9..c90dd989e37f 100644 --- a/packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts +++ b/packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts @@ -28,6 +28,21 @@ describe('OnUncaughtException integration', () => { }); }); + test('should log entire error object to console stderr', done => { + expect.assertions(2); + + const testScriptPath = path.resolve(__dirname, 'log-entire-error-to-console.js'); + + childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stderr) => { + expect(err).not.toBeNull(); + const errString = err?.toString() || ''; + + expect(errString).toContain(stderr); + + done(); + }); + }); + describe('with `exitEvenIfOtherHandlersAreRegistered` set to false', () => { test('should close process on uncaught error with no additional listeners registered', done => { expect.assertions(3); diff --git a/packages/node/src/integrations/utils/errorhandling.ts b/packages/node/src/integrations/utils/errorhandling.ts index e4c7a14924a1..cf52929fa642 100644 --- a/packages/node/src/integrations/utils/errorhandling.ts +++ b/packages/node/src/integrations/utils/errorhandling.ts @@ -10,7 +10,7 @@ const DEFAULT_SHUTDOWN_TIMEOUT = 2000; */ export function logAndExitProcess(error: Error): void { // eslint-disable-next-line no-console - console.error(error && error.stack ? error.stack : error); + console.error(error); const client = getCurrentHub().getClient();