1
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
- import { StackFrame } from '@sentry/types' ;
1
+ import { StackLineParser } from '@sentry/utils' ;
3
2
4
3
// global reference to slice
5
4
const UNKNOWN_FUNCTION = '?' ;
6
5
7
- /**
8
- * An object representing a JavaScript stack trace.
9
- * {Object} StackTrace
10
- * {string} name The name of the thrown exception.
11
- * {string} message The exception error message.
12
- * {TraceKit.StackFrame[]} stack An array of stack frames.
13
- */
14
- export interface StackTrace {
15
- name : string ;
16
- message : string ;
17
- stack : StackFrame [ ] ;
18
- }
19
-
20
- type StackLineParser = ( line : string ) => StackFrame | undefined ;
21
-
22
6
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
23
7
const chromeRegex =
24
8
/ ^ \s * a t (?: ( .* ?) ? \( (?: a d d r e s s a t ) ? ) ? ( (?: f i l e | h t t p s ? | b l o b | c h r o m e - e x t e n s i o n | a d d r e s s | n a t i v e | e v a l | w e b p a c k | < a n o n y m o u s > | [ - a - z ] + : | .* b u n d l e | \/ ) .* ?) (?: : ( \d + ) ) ? (?: : ( \d + ) ) ? \) ? \s * $ / i;
25
9
const chromeEvalRegex = / \( ( \S * ) (?: : ( \d + ) ) (?: : ( \d + ) ) \) / ;
26
10
27
- const chrome : StackLineParser = line => {
11
+ export const chrome : StackLineParser = line => {
28
12
const parts = chromeRegex . exec ( line ) ;
29
13
30
14
if ( parts ) {
@@ -63,7 +47,7 @@ const geckoREgex =
63
47
/ ^ \s * ( .* ?) (?: \( ( .* ?) \) ) ? (?: ^ | @ ) ? ( (?: f i l e | h t t p s ? | b l o b | c h r o m e | w e b p a c k | r e s o u r c e | m o z - e x t e n s i o n | c a p a c i t o r ) .* ?: \/ .* ?| \[ n a t i v e c o d e \] | [ ^ @ ] * (?: b u n d l e | \d + \. j s ) | \/ [ \w \- . / = ] + ) (?: : ( \d + ) ) ? (?: : ( \d + ) ) ? \s * $ / i;
64
48
const geckoEvalRegex = / ( \S + ) l i n e ( \d + ) (?: > e v a l l i n e \d + ) * > e v a l / i;
65
49
66
- const gecko : StackLineParser = line => {
50
+ export const gecko : StackLineParser = line => {
67
51
const parts = geckoREgex . exec ( line ) ;
68
52
69
53
if ( parts ) {
@@ -98,7 +82,7 @@ const gecko: StackLineParser = line => {
98
82
const winjsRegex =
99
83
/ ^ \s * a t (?: ( (?: \[ o b j e c t o b j e c t \] ) ? .+ ) ) ? \( ? ( (?: f i l e | m s - a p p x | h t t p s ? | w e b p a c k | b l o b ) : .* ?) : ( \d + ) (?: : ( \d + ) ) ? \) ? \s * $ / i;
100
84
101
- const winjs : StackLineParser = line => {
85
+ export const winjs : StackLineParser = line => {
102
86
const parts = winjsRegex . exec ( line ) ;
103
87
104
88
return parts
@@ -113,7 +97,7 @@ const winjs: StackLineParser = line => {
113
97
114
98
const opera10Regex = / l i n e ( \d + ) .* s c r i p t (?: i n ) ? ( \S + ) (?: : i n f u n c t i o n ( \S + ) ) ? $ / i;
115
99
116
- const opera10 : StackLineParser = line => {
100
+ export const opera10 : StackLineParser = line => {
117
101
const parts = opera10Regex . exec ( line ) ;
118
102
119
103
return parts
@@ -128,7 +112,7 @@ const opera10: StackLineParser = line => {
128
112
const opera11Regex =
129
113
/ l i n e ( \d + ) , c o l u m n ( \d + ) \s * (?: i n (?: < a n o n y m o u s f u n c t i o n : ( [ ^ > ] + ) > | ( [ ^ ) ] + ) ) \( .* \) ) ? i n ( .* ) : \s * $ / i;
130
114
131
- const opera11 : StackLineParser = line => {
115
+ export const opera11 : StackLineParser = line => {
132
116
const parts = opera11Regex . exec ( line ) ;
133
117
134
118
return parts
@@ -141,53 +125,6 @@ const opera11: StackLineParser = line => {
141
125
: undefined ;
142
126
} ;
143
127
144
- // Based on our own mapping pattern - https://github.com/getsentry/sentry/blob/9f08305e09866c8bd6d0c24f5b0aabdd7dd6c59c/src/sentry/lang/javascript/errormapping.py#L83-L108
145
- const reactMinifiedRegexp = / M i n i f i e d R e a c t e r r o r # \d + ; / i;
146
-
147
- /** JSDoc */
148
- export function computeStackTrace ( ex : Error & { framesToPop ?: number ; stacktrace ?: string } ) : StackTrace {
149
- let frames : StackFrame [ ] = [ ] ;
150
- let popSize = 0 ;
151
-
152
- if ( ex ) {
153
- if ( typeof ex . framesToPop === 'number' ) {
154
- popSize = ex . framesToPop ;
155
- } else if ( reactMinifiedRegexp . test ( ex . message ) ) {
156
- popSize = 1 ;
157
- }
158
- }
159
-
160
- try {
161
- // Access and store the stacktrace property before doing ANYTHING
162
- // else to it because Opera is not very good at providing it
163
- // reliably in other circumstances.
164
- const stacktrace = ex . stacktrace || ex . stack || '' ;
165
-
166
- for ( const line of stacktrace . split ( '\n' ) ) {
167
- for ( const parser of [ opera10 , opera11 , chrome , winjs , gecko ] ) {
168
- const frame = parser ( line ) ;
169
-
170
- if ( frame ) {
171
- frames . push ( frame ) ;
172
- break ;
173
- }
174
- }
175
- }
176
- } catch ( e ) {
177
- // no-empty
178
- }
179
-
180
- if ( frames . length && popSize > 0 ) {
181
- frames = frames . slice ( popSize ) ;
182
- }
183
-
184
- return {
185
- message : extractMessage ( ex ) ,
186
- name : ex && ex . name ,
187
- stack : frames ,
188
- } ;
189
- }
190
-
191
128
/**
192
129
* Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.
193
130
* What it means, is that instead of format like:
@@ -205,7 +142,7 @@ export function computeStackTrace(ex: Error & { framesToPop?: number; stacktrace
205
142
*
206
143
* Because of that, it won't be captured by `chrome` RegExp and will fall into `Gecko` branch.
207
144
* This function is extracted so that we can use it in both places without duplicating the logic.
208
- * Unfortunatelly "just" changing RegExp is too complicated now and making it pass all tests
145
+ * Unfortunately "just" changing RegExp is too complicated now and making it pass all tests
209
146
* and fix this case seems like an impossible, or at least way too time-consuming task.
210
147
*/
211
148
const extractSafariExtensionDetails = ( func : string , filename : string ) : [ string , string ] => {
@@ -219,20 +156,3 @@ const extractSafariExtensionDetails = (func: string, filename: string): [string,
219
156
]
220
157
: [ func , filename ] ;
221
158
} ;
222
-
223
- /**
224
- * There are cases where stacktrace.message is an Event object
225
- * https://github.com/getsentry/sentry-javascript/issues/1949
226
- * In this specific case we try to extract stacktrace.message.error.message
227
- */
228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
- function extractMessage ( ex : any ) : string {
230
- const message = ex && ex . message ;
231
- if ( ! message ) {
232
- return 'No error message' ;
233
- }
234
- if ( message . error && typeof message . error . message === 'string' ) {
235
- return message . error . message ;
236
- }
237
- return message ;
238
- }
0 commit comments