Skip to content

fix(node): save string exception as message of synthetic #2837

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

Merged
merged 1 commit into from
Aug 26, 2020
Merged
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
1 change: 1 addition & 0 deletions packages/node/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class NodeBackend extends BaseBackend<NodeOptions> {
// This handles when someone does: `throw "something awesome";`
// We use synthesized Error here so we can extract a (rough) stack trace.
ex = (hint && hint.syntheticException) || new Error(exception as string);
(ex as Error).message = exception;
}
mechanism.synthetic = true;
}
Expand Down
30 changes: 29 additions & 1 deletion packages/node/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('SentryNode', () => {
});

test('capture an exception', done => {
expect.assertions(5);
expect.assertions(6);
getCurrentHub().bindClient(
new NodeClient({
beforeSend: (event: Event) => {
Expand All @@ -111,6 +111,7 @@ describe('SentryNode', () => {
expect(event.exception!.values![0]).not.toBeUndefined();
expect(event.exception!.values![0].stacktrace!).not.toBeUndefined();
expect(event.exception!.values![0].stacktrace!.frames![2]).not.toBeUndefined();
expect(event.exception!.values![0].value).toEqual('test');
done();
return null;
},
Expand All @@ -127,6 +128,33 @@ describe('SentryNode', () => {
}
});

test('capture a string exception', done => {
expect.assertions(6);
getCurrentHub().bindClient(
new NodeClient({
beforeSend: (event: Event) => {
expect(event.tags).toEqual({ test: '1' });
expect(event.exception).not.toBeUndefined();
expect(event.exception!.values![0]).not.toBeUndefined();
expect(event.exception!.values![0].stacktrace!).not.toBeUndefined();
expect(event.exception!.values![0].stacktrace!.frames![2]).not.toBeUndefined();
expect(event.exception!.values![0].value).toEqual('test string exception');
done();
return null;
},
dsn,
}),
);
configureScope((scope: Scope) => {
scope.setTag('test', '1');
});
try {
throw 'test string exception';
} catch (e) {
captureException(e);
}
});

test('capture an exception no pre/post context', done => {
expect.assertions(10);
getCurrentHub().bindClient(
Expand Down