File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -115,7 +115,12 @@ function _extractErrorData(
115
115
// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
116
116
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
117
117
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
+ }
119
124
}
120
125
121
126
// Check if someone attached `toJSON` method to grab even more properties (eg. axios is doing that)
Original file line number Diff line number Diff line change @@ -55,9 +55,11 @@ describe('ExtraErrorData()', () => {
55
55
} ) ;
56
56
} ) ;
57
57
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 ' , ( ) => {
59
59
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 ) ;
61
63
62
64
const enhancedEvent = extraErrorData . processEvent ?.(
63
65
event ,
@@ -69,7 +71,12 @@ describe('ExtraErrorData()', () => {
69
71
70
72
expect ( enhancedEvent . contexts ) . toEqual ( {
71
73
TypeError : {
72
- cause : 'SyntaxError: bar' ,
74
+ cause : {
75
+ SyntaxError : {
76
+ baz : 42 ,
77
+ foo : `${ 'a' . repeat ( 250 ) } ...` ,
78
+ } ,
79
+ } ,
73
80
} ,
74
81
} ) ;
75
82
} ) ;
You can’t perform that action at this time.
0 commit comments