11import { exceptionFromError } from '@sentry/browser' ;
22import type {
3+ Client ,
34 DebugImage ,
45 Event ,
56 EventHint ,
@@ -53,35 +54,29 @@ export class NativeLinkedErrors implements Integration {
5354 /**
5455 * @inheritDoc
5556 */
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 ( ) ;
6067 }
6168
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 ) ;
6970 }
7071
7172 /**
7273 * Enriches passed event with linked exceptions and native debug meta images.
7374 */
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 {
8176 if ( ! event . exception || ! event . exception . values || ! hint || ! isInstanceOf ( hint . originalException , Error ) ) {
82- return event ;
77+ return ;
8378 }
84- const { exceptions : linkedErrors , debugImages } = await this . _walkErrorTree (
79+ const { exceptions : linkedErrors , debugImages } = this . _walkErrorTree (
8580 parser ,
8681 limit ,
8782 hint . originalException as ExtendedError ,
@@ -92,25 +87,23 @@ export class NativeLinkedErrors implements Integration {
9287 event . debug_meta = event . debug_meta || { } ;
9388 event . debug_meta . images = event . debug_meta . images || [ ] ;
9489 event . debug_meta . images . push ( ...( debugImages || [ ] ) ) ;
95-
96- return event ;
9790 }
9891
9992 /**
10093 * Walks linked errors and created Sentry exceptions chain.
10194 * Collects debug images from native errors stack frames.
10295 */
103- private async _walkErrorTree (
96+ private _walkErrorTree (
10497 parser : StackParser ,
10598 limit : number ,
10699 error : ExtendedError ,
107100 key : string ,
108101 exceptions : Exception [ ] = [ ] ,
109102 debugImages : DebugImage [ ] = [ ] ,
110- ) : Promise < {
103+ ) : {
111104 exceptions : Exception [ ] ;
112105 debugImages ?: DebugImage [ ] ;
113- } > {
106+ } {
114107 const linkedError = error [ key ] ;
115108 if ( ! linkedError || exceptions . length + 1 >= limit ) {
116109 return {
@@ -126,7 +119,7 @@ export class NativeLinkedErrors implements Integration {
126119 exception = this . _exceptionFromJavaStackElements ( linkedError ) ;
127120 } else if ( 'stackReturnAddresses' in linkedError ) {
128121 // isObjCException
129- const { appleException, appleDebugImages } = await this . _exceptionFromAppleStackReturnAddresses ( linkedError ) ;
122+ const { appleException, appleDebugImages } = this . _exceptionFromAppleStackReturnAddresses ( linkedError ) ;
130123 exception = appleException ;
131124 exceptionDebugImages = appleDebugImages ;
132125 } else if ( isInstanceOf ( linkedError , Error ) ) {
@@ -193,15 +186,15 @@ export class NativeLinkedErrors implements Integration {
193186 /**
194187 * Converts StackAddresses to a SentryException with DebugMetaImages
195188 */
196- private async _exceptionFromAppleStackReturnAddresses ( objCException : {
189+ private _exceptionFromAppleStackReturnAddresses ( objCException : {
197190 name : string ;
198191 message : string ;
199192 stackReturnAddresses : number [ ] ;
200- } ) : Promise < {
193+ } ) : {
201194 appleException : Exception ;
202195 appleDebugImages : DebugImage [ ] ;
203- } > {
204- const nativeStackFrames = await this . _fetchNativeStackFrames ( objCException . stackReturnAddresses ) ;
196+ } {
197+ const nativeStackFrames = this . _fetchNativeStackFrames ( objCException . stackReturnAddresses ) ;
205198
206199 return {
207200 appleException : {
@@ -218,14 +211,14 @@ export class NativeLinkedErrors implements Integration {
218211 /**
219212 * Fetches the native package/image name from the native layer
220213 */
221- private _fetchNativePackage ( ) : Promise < string | null > {
214+ private _fetchNativePackage ( ) : string | null {
222215 return NATIVE . fetchNativePackageName ( ) ;
223216 }
224217
225218 /**
226219 * Fetches native debug image information on iOS
227220 */
228- private _fetchNativeStackFrames ( instructionsAddr : number [ ] ) : Promise < NativeStackFrames | null > {
221+ private _fetchNativeStackFrames ( instructionsAddr : number [ ] ) : NativeStackFrames | null {
229222 return NATIVE . fetchNativeStackFramesBy ( instructionsAddr ) ;
230223 }
231224}
0 commit comments