1
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
- import { captureEvent , convertIntegrationFnToClass , defineIntegration , getClient } from '@sentry/core' ;
3
- import type {
4
- Client ,
5
- Event ,
6
- Integration ,
7
- IntegrationClass ,
8
- IntegrationFn ,
9
- Primitive ,
10
- StackParser ,
11
- } from '@sentry/types' ;
1
+ import { captureEvent , defineIntegration , getClient } from '@sentry/core' ;
2
+ import type { Client , Event , IntegrationFn , Primitive , StackParser } from '@sentry/types' ;
12
3
import {
13
4
addGlobalErrorInstrumentationHandler ,
14
5
addGlobalUnhandledRejectionInstrumentationHandler ,
15
6
getLocationHref ,
16
- isErrorEvent ,
17
7
isPrimitive ,
18
8
isString ,
19
9
logger ,
@@ -57,18 +47,6 @@ const _globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations
57
47
58
48
export const globalHandlersIntegration = defineIntegration ( _globalHandlersIntegration ) ;
59
49
60
- /**
61
- * Global handlers.
62
- * @deprecated Use `globalHandlersIntegration()` instead.
63
- */
64
- // eslint-disable-next-line deprecation/deprecation
65
- export const GlobalHandlers = convertIntegrationFnToClass (
66
- INTEGRATION_NAME ,
67
- globalHandlersIntegration ,
68
- ) as IntegrationClass < Integration & { setup : ( client : Client ) => void } > & {
69
- new ( options ?: Partial < GlobalHandlersIntegrations > ) : Integration ;
70
- } ;
71
-
72
50
function _installGlobalOnErrorHandler ( client : Client ) : void {
73
51
addGlobalErrorInstrumentationHandler ( data => {
74
52
const { stackParser, attachStacktrace } = getOptions ( ) ;
@@ -79,15 +57,12 @@ function _installGlobalOnErrorHandler(client: Client): void {
79
57
80
58
const { msg, url, line, column, error } = data ;
81
59
82
- const event =
83
- error === undefined && isString ( msg )
84
- ? _eventFromIncompleteOnError ( msg , url , line , column )
85
- : _enhanceEventWithInitialFrame (
86
- eventFromUnknownInput ( stackParser , error || msg , undefined , attachStacktrace , false ) ,
87
- url ,
88
- line ,
89
- column ,
90
- ) ;
60
+ const event = _enhanceEventWithInitialFrame (
61
+ eventFromUnknownInput ( stackParser , error || msg , undefined , attachStacktrace , false ) ,
62
+ url ,
63
+ line ,
64
+ column ,
65
+ ) ;
91
66
92
67
event . level = 'error' ;
93
68
@@ -132,24 +107,23 @@ function _getUnhandledRejectionError(error: unknown): unknown {
132
107
return error ;
133
108
}
134
109
135
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
136
- const e = error as any ;
137
-
138
110
// dig the object of the rejection out of known event types
139
111
try {
112
+ type ErrorWithReason = { reason : unknown } ;
140
113
// PromiseRejectionEvents store the object of the rejection under 'reason'
141
114
// see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
142
- if ( 'reason' in e ) {
143
- return e . reason ;
115
+ if ( 'reason' in ( error as ErrorWithReason ) ) {
116
+ return ( error as ErrorWithReason ) . reason ;
144
117
}
145
118
119
+ type CustomEventWithDetail = { detail : { reason : unknown } } ;
146
120
// something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
147
121
// to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
148
122
// the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
149
123
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
150
124
// https://github.com/getsentry/sentry-javascript/issues/2380
151
- else if ( 'detail' in e && 'reason' in e . detail ) {
152
- return e . detail . reason ;
125
+ if ( 'detail' in ( error as CustomEventWithDetail ) && 'reason' in ( error as CustomEventWithDetail ) . detail ) {
126
+ return ( error as CustomEventWithDetail ) . detail . reason ;
153
127
}
154
128
} catch { } // eslint-disable-line no-empty
155
129
@@ -176,38 +150,6 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
176
150
} ;
177
151
}
178
152
179
- /**
180
- * This function creates a stack from an old, error-less onerror handler.
181
- */
182
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
- function _eventFromIncompleteOnError ( msg : any , url : any , line : any , column : any ) : Event {
184
- const ERROR_TYPES_RE =
185
- / ^ (?: [ U u ] n c a u g h t (?: e x c e p t i o n : ) ? ) ? (?: ( (?: E v a l | I n t e r n a l | R a n g e | R e f e r e n c e | S y n t a x | T y p e | U R I | ) E r r o r ) : ) ? ( .* ) $ / i;
186
-
187
- // If 'message' is ErrorEvent, get real message from inside
188
- let message = isErrorEvent ( msg ) ? msg . message : msg ;
189
- let name = 'Error' ;
190
-
191
- const groups = message . match ( ERROR_TYPES_RE ) ;
192
- if ( groups ) {
193
- name = groups [ 1 ] ;
194
- message = groups [ 2 ] ;
195
- }
196
-
197
- const event = {
198
- exception : {
199
- values : [
200
- {
201
- type : name ,
202
- value : message ,
203
- } ,
204
- ] ,
205
- } ,
206
- } ;
207
-
208
- return _enhanceEventWithInitialFrame ( event , url , line , column ) ;
209
- }
210
-
211
153
// eslint-disable-next-line @typescript-eslint/no-explicit-any
212
154
function _enhanceEventWithInitialFrame ( event : Event , url : any , line : any , column : any ) : Event {
213
155
// event.exception
0 commit comments