Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Log entire error object in OnUncaughtException #8876

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,7 @@
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
});

throw new Error('foo', { cause: 'bar' });
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ describe('OnUncaughtException integration', () => {
});
});

test('should log entire error object to console stderr', done => {
expect.assertions(1);

const testScriptPath = path.resolve(__dirname, 'log-entire-error-to-console.js');

childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stdout, stderr) => {
Fixed Show fixed Hide fixed
expect(stderr).toEqual(expect.stringMatching(/Error: foo(\n.*)+ \[cause\]: 'bar'/gm));

done();
});
});

describe('with `exitEvenIfOtherHandlersAreRegistered` set to false', () => {
test('should close process on uncaught error with no additional listeners registered', done => {
expect.assertions(3);
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/utils/errorhandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeClient>();

Expand Down