Skip to content

Commit 53243cf

Browse files
ha1fstack김지오
authored andcommitted
feat
1 parent 93d9b09 commit 53243cf

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/core/src/integrations/extraerrordata.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ function _extractErrorData(
115115
// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
116116
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
117117
if (captureErrorCause && error.cause !== undefined) {
118-
extraErrorInfo.cause = isError(error.cause) ? error.cause.toString() : error.cause;
118+
if (isError(error.cause)) {
119+
const causeName = error.cause.name || error.cause.constructor.name;
120+
extraErrorInfo.cause = { [causeName]: _extractErrorData(error.cause as ExtendedError, false, maxValueLength) };
121+
} else {
122+
extraErrorInfo.cause = error.cause;
123+
}
119124
}
120125

121126
// Check if someone attached `toJSON` method to grab even more properties (eg. axios is doing that)

packages/core/test/lib/integrations/extraerrordata.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ describe('ExtraErrorData()', () => {
5555
});
5656
});
5757

58-
it('doesnt choke on linked errors and stringify names instead', () => {
58+
it('should extract error data from the error cause with the same policy', () => {
5959
const error = new TypeError('foo') as ExtendedError;
60-
error.cause = new SyntaxError('bar');
60+
error.cause = new SyntaxError('bar') as ExtendedError;
61+
error.cause.baz = 42;
62+
error.cause.foo = 'a'.repeat(300);
6163

6264
const enhancedEvent = extraErrorData.processEvent?.(
6365
event,
@@ -69,7 +71,12 @@ describe('ExtraErrorData()', () => {
6971

7072
expect(enhancedEvent.contexts).toEqual({
7173
TypeError: {
72-
cause: 'SyntaxError: bar',
74+
cause: {
75+
SyntaxError: {
76+
baz: 42,
77+
foo: `${'a'.repeat(250)}...`,
78+
},
79+
},
7380
},
7481
});
7582
});

0 commit comments

Comments
 (0)