Skip to content

Commit 6142ef1

Browse files
authored
feat(v8/browser): Remove _eventFromIncompleteOnError usage (#10553)
closes #5842 Also deletes `GlobalHandlers` integration deprecated export while I'm here.
1 parent 465bd29 commit 6142ef1

File tree

3 files changed

+15
-74
lines changed

3 files changed

+15
-74
lines changed

packages/browser/src/exports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ export { linkedErrorsIntegration } from './integrations/linkederrors';
109109
export { browserApiErrorsIntegration } from './integrations/trycatch';
110110

111111
// eslint-disable-next-line deprecation/deprecation
112-
export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';
112+
export { TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
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';
123
import {
134
addGlobalErrorInstrumentationHandler,
145
addGlobalUnhandledRejectionInstrumentationHandler,
156
getLocationHref,
16-
isErrorEvent,
177
isPrimitive,
188
isString,
199
logger,
@@ -57,18 +47,6 @@ const _globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations
5747

5848
export const globalHandlersIntegration = defineIntegration(_globalHandlersIntegration);
5949

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-
7250
function _installGlobalOnErrorHandler(client: Client): void {
7351
addGlobalErrorInstrumentationHandler(data => {
7452
const { stackParser, attachStacktrace } = getOptions();
@@ -79,15 +57,12 @@ function _installGlobalOnErrorHandler(client: Client): void {
7957

8058
const { msg, url, line, column, error } = data;
8159

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+
);
9166

9267
event.level = 'error';
9368

@@ -132,24 +107,23 @@ function _getUnhandledRejectionError(error: unknown): unknown {
132107
return error;
133108
}
134109

135-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
136-
const e = error as any;
137-
138110
// dig the object of the rejection out of known event types
139111
try {
112+
type ErrorWithReason = { reason: unknown };
140113
// PromiseRejectionEvents store the object of the rejection under 'reason'
141114
// 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;
144117
}
145118

119+
type CustomEventWithDetail = { detail: { reason: unknown } };
146120
// something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
147121
// to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
148122
// the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
149123
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
150124
// 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;
153127
}
154128
} catch {} // eslint-disable-line no-empty
155129

@@ -176,38 +150,6 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
176150
};
177151
}
178152

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-
/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/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-
211153
// eslint-disable-next-line @typescript-eslint/no-explicit-any
212154
function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column: any): Event {
213155
// event.exception

packages/browser/src/integrations/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable deprecation/deprecation */
2-
export { GlobalHandlers } from './globalhandlers';
32
export { TryCatch } from './trycatch';
43
export { Breadcrumbs } from './breadcrumbs';
54
export { LinkedErrors } from './linkederrors';

0 commit comments

Comments
 (0)