diff --git a/packages/browser/src/backend.ts b/packages/browser/src/backend.ts index 88d0bba7bc75..3ca50f2b2fe7 100644 --- a/packages/browser/src/backend.ts +++ b/packages/browser/src/backend.ts @@ -40,13 +40,13 @@ export class BrowserBackend extends BaseBackend { * @inheritDoc */ public eventFromException(exception: unknown, hint?: EventHint): PromiseLike { - return eventFromException(this._options, exception, hint); + return eventFromException(exception, hint, this._options.attachStacktrace); } /** * @inheritDoc */ public eventFromMessage(message: string, level: Severity = Severity.Info, hint?: EventHint): PromiseLike { - return eventFromMessage(this._options, message, level, hint); + return eventFromMessage(message, level, hint, this._options.attachStacktrace); } /** diff --git a/packages/browser/src/eventbuilder.ts b/packages/browser/src/eventbuilder.ts index 051cec270ca4..ef615d2cedcf 100644 --- a/packages/browser/src/eventbuilder.ts +++ b/packages/browser/src/eventbuilder.ts @@ -1,4 +1,4 @@ -import { Event, EventHint, Options, Severity } from '@sentry/types'; +import { Event, EventHint, Severity } from '@sentry/types'; import { addExceptionMechanism, addExceptionTypeValue, @@ -17,11 +17,13 @@ import { eventFromError, eventFromPlainObject, parseStackFrames } from './parser * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`. * @hidden */ -export function eventFromException(options: Options, exception: unknown, hint?: EventHint): PromiseLike { +export function eventFromException( + exception: unknown, + hint?: EventHint, + attachStacktrace?: boolean, +): PromiseLike { const syntheticException = (hint && hint.syntheticException) || undefined; - const event = eventFromUnknownInput(exception, syntheticException, { - attachStacktrace: options.attachStacktrace, - }); + const event = eventFromUnknownInput(exception, syntheticException, attachStacktrace); addExceptionMechanism(event); // defaults to { type: 'generic', handled: true } event.level = Severity.Error; if (hint && hint.event_id) { @@ -35,15 +37,13 @@ export function eventFromException(options: Options, exception: unknown, hint?: * @hidden */ export function eventFromMessage( - options: Options, message: string, level: Severity = Severity.Info, hint?: EventHint, + attachStacktrace?: boolean, ): PromiseLike { const syntheticException = (hint && hint.syntheticException) || undefined; - const event = eventFromString(message, syntheticException, { - attachStacktrace: options.attachStacktrace, - }); + const event = eventFromString(message, syntheticException, attachStacktrace); event.level = level; if (hint && hint.event_id) { event.event_id = hint.event_id; @@ -57,10 +57,8 @@ export function eventFromMessage( export function eventFromUnknownInput( exception: unknown, syntheticException?: Error, - options: { - isRejection?: boolean; - attachStacktrace?: boolean; - } = {}, + attachStacktrace?: boolean, + isUnhandledRejection?: boolean, ): Event { let event: Event; @@ -85,7 +83,7 @@ export function eventFromUnknownInput( } else { const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException'); const message = domException.message ? `${name}: ${domException.message}` : name; - event = eventFromString(message, syntheticException, options); + event = eventFromString(message, syntheticException, attachStacktrace); addExceptionTypeValue(event, message); } if ('code' in domException) { @@ -103,7 +101,7 @@ export function eventFromUnknownInput( // it manually. This will allow us to group events based on top-level keys which is much better than creating a new // group on any key/value change. const objectException = exception as Record; - event = eventFromPlainObject(objectException, syntheticException, options.isRejection); + event = eventFromPlainObject(objectException, syntheticException, isUnhandledRejection); addExceptionMechanism(event, { synthetic: true, }); @@ -119,7 +117,7 @@ export function eventFromUnknownInput( // - a plain Object // // So bail out and capture it as a simple message: - event = eventFromString(exception as string, syntheticException, options); + event = eventFromString(exception as string, syntheticException, attachStacktrace); addExceptionTypeValue(event, `${exception}`, undefined); addExceptionMechanism(event, { synthetic: true, @@ -131,18 +129,12 @@ export function eventFromUnknownInput( /** * @hidden */ -export function eventFromString( - input: string, - syntheticException?: Error, - options: { - attachStacktrace?: boolean; - } = {}, -): Event { +export function eventFromString(input: string, syntheticException?: Error, attachStacktrace?: boolean): Event { const event: Event = { message: input, }; - if (options.attachStacktrace && syntheticException) { + if (attachStacktrace && syntheticException) { const frames = parseStackFrames(syntheticException); if (frames.length) { event.stacktrace = { frames }; diff --git a/packages/browser/src/integrations/globalhandlers.ts b/packages/browser/src/integrations/globalhandlers.ts index 07d8208f1f66..c3cb56a8f341 100644 --- a/packages/browser/src/integrations/globalhandlers.ts +++ b/packages/browser/src/integrations/globalhandlers.ts @@ -92,10 +92,7 @@ function _installGlobalOnErrorHandler(): void { error === undefined && isString(msg) ? _eventFromIncompleteOnError(msg, url, line, column) : _enhanceEventWithInitialFrame( - eventFromUnknownInput(error || msg, undefined, { - attachStacktrace, - isRejection: false, - }), + eventFromUnknownInput(error || msg, undefined, attachStacktrace, false), url, line, column, @@ -145,10 +142,7 @@ function _installGlobalOnUnhandledRejectionHandler(): void { const event = isPrimitive(error) ? _eventFromRejectionWithPrimitive(error) - : eventFromUnknownInput(error, undefined, { - attachStacktrace, - isRejection: true, - }); + : eventFromUnknownInput(error, undefined, attachStacktrace, true); event.level = Severity.Error; diff --git a/packages/browser/src/parsers.ts b/packages/browser/src/parsers.ts index 0fbefca98b60..ff161c0ec3c3 100644 --- a/packages/browser/src/parsers.ts +++ b/packages/browser/src/parsers.ts @@ -35,15 +35,15 @@ export function exceptionFromError(ex: Error): Exception { export function eventFromPlainObject( exception: Record, syntheticException?: Error, - rejection?: boolean, + isUnhandledRejection?: boolean, ): Event { const event: Event = { exception: { values: [ { - type: isEvent(exception) ? exception.constructor.name : rejection ? 'UnhandledRejection' : 'Error', + type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error', value: `Non-Error ${ - rejection ? 'promise rejection' : 'exception' + isUnhandledRejection ? 'promise rejection' : 'exception' } captured with keys: ${extractExceptionKeysForMessage(exception)}`, }, ],