1
1
import { addGlobalEventProcessor , getCurrentHub } from '@sentry/hub' ;
2
2
import { Integration , SentryEvent , SentryEventHint } from '@sentry/types' ;
3
- import { isError } from '@sentry/utils/is' ;
4
- import { logger } from '../../../utils/logger' ;
3
+ import { isError , isString } from '@sentry/utils/is' ;
4
+ import { logger } from '@sentry/utils/logger' ;
5
+ import { safeNormalize } from '@sentry/utils/object' ;
5
6
6
7
/**
7
8
* Just an Error object with arbitrary attributes attached to it.
@@ -46,12 +47,19 @@ export class ExtraErrorData implements Integration {
46
47
const errorData = this . extractErrorData ( hint . originalException ) ;
47
48
48
49
if ( errorData ) {
50
+ let extra = {
51
+ ...event . extra ,
52
+ } ;
53
+ const normalizedErrorData = safeNormalize ( errorData ) ;
54
+ if ( ! isString ( normalizedErrorData ) ) {
55
+ extra = {
56
+ ...event . extra ,
57
+ ...normalizedErrorData ,
58
+ } ;
59
+ }
49
60
return {
50
61
...event ,
51
- extra : {
52
- ...event . extra ,
53
- ...errorData ,
54
- } ,
62
+ extra,
55
63
} ;
56
64
}
57
65
@@ -62,6 +70,7 @@ export class ExtraErrorData implements Integration {
62
70
* Extract extra information from the Error object
63
71
*/
64
72
private extractErrorData ( error : ExtendedError ) : { [ key : string ] : unknown } | null {
73
+ let result = null ;
65
74
// We are trying to enhance already existing event, so no harm done if it won't succeed
66
75
try {
67
76
const nativeKeys = [ 'name' , 'message' , 'stack' , 'line' , 'column' , 'fileName' , 'lineNumber' , 'columnNumber' ] ;
@@ -77,15 +86,14 @@ export class ExtraErrorData implements Integration {
77
86
}
78
87
extraErrorInfo [ key ] = value ;
79
88
}
80
- return {
89
+ result = {
81
90
[ name ] : extraErrorInfo ,
82
91
} ;
83
92
}
84
-
85
- return null ;
86
93
} catch ( oO ) {
87
94
logger . error ( 'Unable to extract extra data from the Error object:' , oO ) ;
88
- return null ;
89
95
}
96
+
97
+ return result ;
90
98
}
91
99
}
0 commit comments