@@ -57,37 +57,38 @@ export function stackParserFromStackParserOptions(stackParser: StackParser | Sta
57
57
}
58
58
59
59
/**
60
+ * Removes Sentry frames from the top and bottom of the stack if present and enforces a limit of max number of frames.
61
+ * Assumes stack input is ordered from top to bottom and returns the reverse representation so call site of the
62
+ * function that caused the crash is the last frame in the array.
60
63
* @hidden
61
64
*/
62
- export function stripSentryFramesAndReverse ( stack : StackFrame [ ] ) : StackFrame [ ] {
65
+ export function stripSentryFramesAndReverse ( stack : ReadonlyArray < StackFrame > ) : StackFrame [ ] {
63
66
if ( ! stack . length ) {
64
67
return [ ] ;
65
68
}
66
69
67
- let localStack = stack ;
68
-
69
- const firstFrameFunction = localStack [ 0 ] . function || '' ;
70
- const lastFrameFunction = localStack [ localStack . length - 1 ] . function || '' ;
70
+ const localStack = stack . slice ( 0 , STACKTRACE_LIMIT ) ;
71
71
72
+ const lastFrameFunction = localStack [ localStack . length - 1 ] . function ;
72
73
// If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
73
- if ( firstFrameFunction . indexOf ( 'captureMessage' ) !== - 1 || firstFrameFunction . indexOf ( 'captureException' ) !== - 1 ) {
74
- localStack = localStack . slice ( 1 ) ;
74
+ if ( lastFrameFunction && / s e n t r y W r a p p e d / . test ( lastFrameFunction ) ) {
75
+ localStack . pop ( ) ;
75
76
}
76
77
78
+ // Reversing in the middle of the procedure allows us to just pop the values off the stack
79
+ localStack . reverse ( ) ;
80
+
81
+ const firstFrameFunction = localStack [ localStack . length - 1 ] . function ;
77
82
// If stack ends with one of our internal API calls, remove it (ends, meaning it's the bottom of the stack - aka top-most call)
78
- if ( lastFrameFunction . indexOf ( 'sentryWrapped' ) !== - 1 ) {
79
- localStack = localStack . slice ( 0 , - 1 ) ;
83
+ if ( firstFrameFunction && / c a p t u r e M e s s a g e | c a p t u r e E x c e p t i o n / . test ( firstFrameFunction ) ) {
84
+ localStack . pop ( ) ;
80
85
}
81
86
82
- // The frame where the crash happened, should be the last entry in the array
83
- return localStack
84
- . slice ( 0 , STACKTRACE_LIMIT )
85
- . map ( frame => ( {
86
- ...frame ,
87
- filename : frame . filename || localStack [ 0 ] . filename ,
88
- function : frame . function || '?' ,
89
- } ) )
90
- . reverse ( ) ;
87
+ return localStack . map ( frame => ( {
88
+ ...frame ,
89
+ filename : frame . filename || localStack [ localStack . length - 1 ] . filename ,
90
+ function : frame . function || '?' ,
91
+ } ) ) ;
91
92
}
92
93
93
94
const defaultFunctionName = '<anonymous>' ;
0 commit comments