@@ -2,9 +2,7 @@ import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';
22import type { Event , EventHint , Integration , StackFrame } from '@sentry/types' ;
33import { addContextToFrame , logger } from '@sentry/utils' ;
44
5- const INTERNAL_CALLSITES_REGEX = new RegExp (
6- [ 'ReactNativeRenderer-dev\\.js$' , 'MessageQueue\\.js$' ] . join ( '|' )
7- ) ;
5+ const INTERNAL_CALLSITES_REGEX = new RegExp ( [ 'ReactNativeRenderer-dev\\.js$' , 'MessageQueue\\.js$' ] . join ( '|' ) ) ;
86
97interface GetDevServer {
108 ( ) : { url : string } ;
@@ -78,10 +76,7 @@ export class DebugSymbolicator implements Integration {
7876 * Symbolicates the stack on the device talking to local dev server.
7977 * Mutates the passed event.
8078 */
81- private async _symbolicate (
82- event : Event ,
83- stack : string | undefined
84- ) : Promise < void > {
79+ private async _symbolicate ( event : Event , stack : string | undefined ) : Promise < void > {
8580 try {
8681 // eslint-disable-next-line @typescript-eslint/no-var-requires
8782 const symbolicateStackTrace = require ( 'react-native/Libraries/Core/Devtools/symbolicateStackTrace' ) ;
@@ -99,12 +94,10 @@ export class DebugSymbolicator implements Integration {
9994 const stackWithoutInternalCallsites = newStack . filter (
10095 ( frame : { file ?: string } ) =>
10196 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
102- frame . file && frame . file . match ( INTERNAL_CALLSITES_REGEX ) === null
97+ frame . file && frame . file . match ( INTERNAL_CALLSITES_REGEX ) === null ,
10398 ) ;
10499
105- const symbolicatedFrames = await this . _convertReactNativeFramesToSentryFrames (
106- stackWithoutInternalCallsites
107- ) ;
100+ const symbolicatedFrames = await this . _convertReactNativeFramesToSentryFrames ( stackWithoutInternalCallsites ) ;
108101 this . _replaceFramesInEvent ( event , symbolicatedFrames ) ;
109102 } else {
110103 logger . error ( 'The stack is null' ) ;
@@ -120,9 +113,7 @@ export class DebugSymbolicator implements Integration {
120113 * Converts ReactNativeFrames to frames in the Sentry format
121114 * @param frames ReactNativeFrame[]
122115 */
123- private async _convertReactNativeFramesToSentryFrames (
124- frames : ReactNativeFrame [ ]
125- ) : Promise < StackFrame [ ] > {
116+ private async _convertReactNativeFramesToSentryFrames ( frames : ReactNativeFrame [ ] ) : Promise < StackFrame [ ] > {
126117 let getDevServer : GetDevServer ;
127118 try {
128119 getDevServer = require ( 'react-native/Libraries/Core/Devtools/getDevServer' ) ;
@@ -132,44 +123,40 @@ export class DebugSymbolicator implements Integration {
132123 // Below you will find lines marked with :HACK to prevent showing errors in the sentry ui
133124 // But since this is a debug only feature: This is Fine (TM)
134125 return Promise . all (
135- frames . map (
136- async ( frame : ReactNativeFrame ) : Promise < StackFrame > => {
137- let inApp = ! ! frame . column && ! ! frame . lineNumber ;
138- inApp =
139- inApp &&
140- frame . file !== undefined &&
141- ! frame . file . includes ( 'node_modules' ) &&
142- ! frame . file . includes ( 'native code' ) ;
143-
144- const newFrame : StackFrame = {
145- colno : frame . column ,
146- filename : frame . file ,
147- function : frame . methodName ,
148- in_app : inApp ,
149- lineno : inApp ? frame . lineNumber : undefined , // :HACK
150- platform : inApp ? 'javascript' : 'node' , // :HACK
151- } ;
152-
153- // The upstream `[email protected] ` delegates parsing of stacks to `stacktrace-parser`, which is buggy and 154- // leaves a trailing `(address at` in the function name.
155- // `[email protected] ` seems to have custom logic to parse hermes frames specially. 156- // Anyway, all we do here is throw away the bogus suffix.
157- if ( newFrame . function ) {
158- const addressAtPos = newFrame . function . indexOf ( '(address at' ) ;
159- if ( addressAtPos >= 0 ) {
160- newFrame . function = newFrame . function
161- . substr ( 0 , addressAtPos )
162- . trim ( ) ;
163- }
164- }
165-
166- if ( inApp ) {
167- await this . _addSourceContext ( newFrame , getDevServer ) ;
126+ frames . map ( async ( frame : ReactNativeFrame ) : Promise < StackFrame > => {
127+ let inApp = ! ! frame . column && ! ! frame . lineNumber ;
128+ inApp =
129+ inApp &&
130+ frame . file !== undefined &&
131+ ! frame . file . includes ( 'node_modules' ) &&
132+ ! frame . file . includes ( 'native code' ) ;
133+
134+ const newFrame : StackFrame = {
135+ colno : frame . column ,
136+ filename : frame . file ,
137+ function : frame . methodName ,
138+ in_app : inApp ,
139+ lineno : inApp ? frame . lineNumber : undefined , // :HACK
140+ platform : inApp ? 'javascript' : 'node' , // :HACK
141+ } ;
142+
143+ // The upstream `[email protected] ` delegates parsing of stacks to `stacktrace-parser`, which is buggy and 144+ // leaves a trailing `(address at` in the function name.
145+ // `[email protected] ` seems to have custom logic to parse hermes frames specially. 146+ // Anyway, all we do here is throw away the bogus suffix.
147+ if ( newFrame . function ) {
148+ const addressAtPos = newFrame . function . indexOf ( '(address at' ) ;
149+ if ( addressAtPos >= 0 ) {
150+ newFrame . function = newFrame . function . substr ( 0 , addressAtPos ) . trim ( ) ;
168151 }
152+ }
169153
170- return newFrame ;
154+ if ( inApp ) {
155+ await this . _addSourceContext ( newFrame , getDevServer ) ;
171156 }
172- )
157+
158+ return newFrame ;
159+ } ) ,
173160 ) ;
174161 }
175162
@@ -195,23 +182,17 @@ export class DebugSymbolicator implements Integration {
195182 * @param frame StackFrame
196183 * @param getDevServer function from RN to get DevServer URL
197184 */
198- private async _addSourceContext (
199- frame : StackFrame ,
200- getDevServer ?: GetDevServer
201- ) : Promise < void > {
185+ private async _addSourceContext ( frame : StackFrame , getDevServer ?: GetDevServer ) : Promise < void > {
202186 let response ;
203187
204188 const segments = frame . filename ?. split ( '/' ) ?? [ ] ;
205189
206190 if ( getDevServer ) {
207191 for ( const idx in segments ) {
208192 if ( Object . prototype . hasOwnProperty . call ( segments , idx ) ) {
209- response = await fetch (
210- `${ getDevServer ( ) . url } ${ segments . slice ( - idx ) . join ( '/' ) } ` ,
211- {
212- method : 'GET' ,
213- }
214- ) ;
193+ response = await fetch ( `${ getDevServer ( ) . url } ${ segments . slice ( - idx ) . join ( '/' ) } ` , {
194+ method : 'GET' ,
195+ } ) ;
215196
216197 if ( response . ok ) {
217198 break ;
0 commit comments