@@ -64,28 +64,31 @@ export function stripSentryFramesAndReverse(stack: StackFrame[]): StackFrame[] {
64
64
65
65
let localStack = stack ;
66
66
67
- const firstFrameFunction = localStack [ 0 ] . function || '' ;
68
- const lastFrameFunction = localStack [ localStack . length - 1 ] . function || '' ;
69
-
70
- // If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
71
- if ( firstFrameFunction . indexOf ( 'captureMessage' ) !== - 1 || firstFrameFunction . indexOf ( 'captureException' ) !== - 1 ) {
72
- localStack = localStack . slice ( 1 ) ;
67
+ if ( stack . length >= STACKTRACE_LIMIT ) {
68
+ localStack . slice ( 0 , STACKTRACE_LIMIT ) ;
73
69
}
74
70
71
+ const lastFrameFunction = localStack [ localStack . length - 1 ] . function ;
75
72
// 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)
76
- if ( lastFrameFunction . indexOf ( 'sentryWrapped' ) !== - 1 ) {
77
- localStack = localStack . slice ( 0 , - 1 ) ;
73
+ if ( lastFrameFunction && / s e n t r y W r a p p e d / . test ( lastFrameFunction ) ) {
74
+ localStack . pop ( ) ;
75
+ }
76
+
77
+ // Reversing in the middle of the procedure allows us to just pop the values off the stack
78
+ localStack = localStack . reverse ( ) ;
79
+
80
+ const firstFrameFunction = localStack [ localStack . length - 1 ] . function ;
81
+ // If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
82
+ 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 ) ) {
83
+ localStack . pop ( ) ;
78
84
}
79
85
80
86
// The frame where the crash happened, should be the last entry in the array
81
- return localStack
82
- . slice ( 0 , STACKTRACE_LIMIT )
83
- . map ( frame => ( {
84
- ...frame ,
85
- filename : frame . filename || localStack [ 0 ] . filename ,
86
- function : frame . function || '?' ,
87
- } ) )
88
- . reverse ( ) ;
87
+ return localStack . map ( frame => ( {
88
+ ...frame ,
89
+ filename : frame . filename || localStack [ 0 ] . filename ,
90
+ function : frame . function || '?' ,
91
+ } ) ) ;
89
92
}
90
93
91
94
const defaultFunctionName = '<anonymous>' ;
0 commit comments