|
1 | | -import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/core'; |
| 1 | +import type { Client, Event, IntegrationFn, Primitive, StackFrame, StackParser } from '@sentry/core'; |
2 | 2 | import { |
3 | 3 | UNKNOWN_FUNCTION, |
4 | 4 | addGlobalErrorInstrumentationHandler, |
@@ -155,24 +155,22 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event { |
155 | 155 |
|
156 | 156 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
157 | 157 | 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 | + } |
168 | 166 |
|
169 | 167 | const colno = isNaN(parseInt(column, 10)) ? undefined : column; |
170 | 168 | const lineno = isNaN(parseInt(line, 10)) ? undefined : line; |
171 | 169 | const filename = isString(url) && url.length > 0 ? url : getLocationHref(); |
172 | 170 |
|
173 | 171 | // event.exception.values[0].stacktrace.frames |
174 | | - if (ev0sf.length === 0) { |
175 | | - ev0sf.push({ |
| 172 | + if (frames.length === 0) { |
| 173 | + frames.push({ |
176 | 174 | colno, |
177 | 175 | filename, |
178 | 176 | function: UNKNOWN_FUNCTION, |
|
0 commit comments