1
1
import { exceptionFromError } from '@sentry/browser' ;
2
2
import type {
3
+ Client ,
3
4
DebugImage ,
4
5
Event ,
5
6
EventHint ,
@@ -53,35 +54,29 @@ export class NativeLinkedErrors implements Integration {
53
54
/**
54
55
* @inheritDoc
55
56
*/
56
- public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
57
- const client = getCurrentHub ( ) . getClient ( ) ;
58
- if ( ! client ) {
59
- return ;
57
+ public setupOnce ( _addGlobalEventProcessor : ( callback : EventProcessor ) => void , _getCurrentHub : ( ) => Hub ) : void {
58
+ /* noop */
59
+ }
60
+
61
+ /**
62
+ * @inheritDoc
63
+ */
64
+ public preprocessEvent ( event : Event , hint : EventHint | undefined , client : Client ) : void {
65
+ if ( this . _nativePackage === null ) {
66
+ this . _nativePackage = this . _fetchNativePackage ( ) ;
60
67
}
61
68
62
- addGlobalEventProcessor ( async ( event : Event , hint ?: EventHint ) => {
63
- if ( this . _nativePackage === null ) {
64
- this . _nativePackage = await this . _fetchNativePackage ( ) ;
65
- }
66
- const self = getCurrentHub ( ) . getIntegration ( NativeLinkedErrors ) ;
67
- return self ? this . _handler ( client . getOptions ( ) . stackParser , self . _key , self . _limit , event , hint ) : event ;
68
- } ) ;
69
+ this . _handler ( client . getOptions ( ) . stackParser , this . _key , this . _limit , event , hint ) ;
69
70
}
70
71
71
72
/**
72
73
* Enriches passed event with linked exceptions and native debug meta images.
73
74
*/
74
- private async _handler (
75
- parser : StackParser ,
76
- key : string ,
77
- limit : number ,
78
- event : Event ,
79
- hint ?: EventHint ,
80
- ) : Promise < Event | null > {
75
+ private _handler ( parser : StackParser , key : string , limit : number , event : Event , hint ?: EventHint ) : void {
81
76
if ( ! event . exception || ! event . exception . values || ! hint || ! isInstanceOf ( hint . originalException , Error ) ) {
82
- return event ;
77
+ return ;
83
78
}
84
- const { exceptions : linkedErrors , debugImages } = await this . _walkErrorTree (
79
+ const { exceptions : linkedErrors , debugImages } = this . _walkErrorTree (
85
80
parser ,
86
81
limit ,
87
82
hint . originalException as ExtendedError ,
@@ -92,25 +87,23 @@ export class NativeLinkedErrors implements Integration {
92
87
event . debug_meta = event . debug_meta || { } ;
93
88
event . debug_meta . images = event . debug_meta . images || [ ] ;
94
89
event . debug_meta . images . push ( ...( debugImages || [ ] ) ) ;
95
-
96
- return event ;
97
90
}
98
91
99
92
/**
100
93
* Walks linked errors and created Sentry exceptions chain.
101
94
* Collects debug images from native errors stack frames.
102
95
*/
103
- private async _walkErrorTree (
96
+ private _walkErrorTree (
104
97
parser : StackParser ,
105
98
limit : number ,
106
99
error : ExtendedError ,
107
100
key : string ,
108
101
exceptions : Exception [ ] = [ ] ,
109
102
debugImages : DebugImage [ ] = [ ] ,
110
- ) : Promise < {
103
+ ) : {
111
104
exceptions : Exception [ ] ;
112
105
debugImages ?: DebugImage [ ] ;
113
- } > {
106
+ } {
114
107
const linkedError = error [ key ] ;
115
108
if ( ! linkedError || exceptions . length + 1 >= limit ) {
116
109
return {
@@ -126,7 +119,7 @@ export class NativeLinkedErrors implements Integration {
126
119
exception = this . _exceptionFromJavaStackElements ( linkedError ) ;
127
120
} else if ( 'stackReturnAddresses' in linkedError ) {
128
121
// isObjCException
129
- const { appleException, appleDebugImages } = await this . _exceptionFromAppleStackReturnAddresses ( linkedError ) ;
122
+ const { appleException, appleDebugImages } = this . _exceptionFromAppleStackReturnAddresses ( linkedError ) ;
130
123
exception = appleException ;
131
124
exceptionDebugImages = appleDebugImages ;
132
125
} else if ( isInstanceOf ( linkedError , Error ) ) {
@@ -193,15 +186,15 @@ export class NativeLinkedErrors implements Integration {
193
186
/**
194
187
* Converts StackAddresses to a SentryException with DebugMetaImages
195
188
*/
196
- private async _exceptionFromAppleStackReturnAddresses ( objCException : {
189
+ private _exceptionFromAppleStackReturnAddresses ( objCException : {
197
190
name : string ;
198
191
message : string ;
199
192
stackReturnAddresses : number [ ] ;
200
- } ) : Promise < {
193
+ } ) : {
201
194
appleException : Exception ;
202
195
appleDebugImages : DebugImage [ ] ;
203
- } > {
204
- const nativeStackFrames = await this . _fetchNativeStackFrames ( objCException . stackReturnAddresses ) ;
196
+ } {
197
+ const nativeStackFrames = this . _fetchNativeStackFrames ( objCException . stackReturnAddresses ) ;
205
198
206
199
return {
207
200
appleException : {
@@ -218,14 +211,14 @@ export class NativeLinkedErrors implements Integration {
218
211
/**
219
212
* Fetches the native package/image name from the native layer
220
213
*/
221
- private _fetchNativePackage ( ) : Promise < string | null > {
214
+ private _fetchNativePackage ( ) : string | null {
222
215
return NATIVE . fetchNativePackageName ( ) ;
223
216
}
224
217
225
218
/**
226
219
* Fetches native debug image information on iOS
227
220
*/
228
- private _fetchNativeStackFrames ( instructionsAddr : number [ ] ) : Promise < NativeStackFrames | null > {
221
+ private _fetchNativeStackFrames ( instructionsAddr : number [ ] ) : NativeStackFrames | null {
229
222
return NATIVE . fetchNativeStackFramesBy ( instructionsAddr ) ;
230
223
}
231
224
}
0 commit comments