Skip to content

Commit c6a5aab

Browse files
committed
ref(browser): Reduce bundle size of GlobalHandlers integration
1 parent 9581a2e commit c6a5aab

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/core';
1+
import type { Client, Event, IntegrationFn, Primitive, StackFrame, StackParser } from '@sentry/core';
22
import {
33
UNKNOWN_FUNCTION,
44
addGlobalErrorInstrumentationHandler,
@@ -155,24 +155,22 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
155155

156156
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157157
function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column: any): Event {
158-
// event.exception
159-
const e = (event.exception = event.exception || {});
160-
// event.exception.values
161-
const ev = (e.values = e.values || []);
162-
// event.exception.values[0]
163-
const ev0 = (ev[0] = ev[0] || {});
164-
// event.exception.values[0].stacktrace
165-
const ev0s = (ev0.stacktrace = ev0.stacktrace || {});
166-
// event.exception.values[0].stacktrace.frames
167-
const ev0sf = (ev0s.frames = ev0s.frames || []);
158+
const frames: StackFrame[] = [];
159+
try {
160+
// @ts-expect-error - this is fine and done to reduce bundle size
161+
// we're catching the error if any of the properties in the chain is undefined
162+
frames.push(event.exception.values[0].stacktrace.frames);
163+
} catch {
164+
// ignored
165+
}
168166

169167
const colno = isNaN(parseInt(column, 10)) ? undefined : column;
170168
const lineno = isNaN(parseInt(line, 10)) ? undefined : line;
171169
const filename = isString(url) && url.length > 0 ? url : getLocationHref();
172170

173171
// event.exception.values[0].stacktrace.frames
174-
if (ev0sf.length === 0) {
175-
ev0sf.push({
172+
if (frames.length === 0) {
173+
frames.push({
176174
colno,
177175
filename,
178176
function: UNKNOWN_FUNCTION,

0 commit comments

Comments
 (0)