rittenhop-dev/versions/5.94.2/node_modules/@sentry/integrations/esm/extraerrordata.js.map

1 line
7.7 KiB
Plaintext
Raw Normal View History

2024-09-23 19:40:12 -04:00
{"version":3,"file":"extraerrordata.js","sources":["../../../src/extraerrordata.ts"],"sourcesContent":["import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';\nimport type {\n Contexts,\n Event,\n EventHint,\n ExtendedError,\n Integration,\n IntegrationClass,\n IntegrationFn,\n} from '@sentry/types';\nimport { addNonEnumerableProperty, isError, isPlainObject, logger, normalize } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from './debug-build';\n\nconst INTEGRATION_NAME = 'ExtraErrorData';\n\ninterface ExtraErrorDataOptions {\n /**\n * The object depth up to which to capture data on error objects.\n */\n depth: number;\n\n /**\n * Whether to capture error causes.\n *\n * More information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause\n */\n captureErrorCause: boolean;\n}\n\nconst _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {}) => {\n const depth = options.depth || 3;\n\n // TODO(v8): Flip the default for this option to true\n const captureErrorCause = options.captureErrorCause || false;\n\n return {\n name: INTEGRATION_NAME,\n // TODO v8: Remove this\n setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n processEvent(event, hint) {\n return _enhanceEventWithErrorData(event, hint, depth, captureErrorCause);\n },\n };\n}) satisfies IntegrationFn;\n\nexport const extraErrorDataIntegration = defineIntegration(_extraErrorDataIntegration);\n\n/**\n * Extract additional data for from original exceptions.\n * @deprecated Use `extraErrorDataIntegration()` instead.\n */\n// eslint-disable-next-line deprecation/deprecation\nexport const ExtraErrorData = convertIntegrationFnToClass(\n INTEGRATION_NAME,\n extraErrorDataIntegration,\n) as IntegrationClass<Integration & { processEvent: (event: Event, hint: EventHint) => Event }> & {\n new (\n options?: Partial<{\n depth: number;\n captureErrorCause: boolean;\n }>,\n ): Integration;\n};\n\nfunction _enhanceEventWithErrorData(\n event: Event,\n hint: EventHint = {},\n depth: number,\n captureErrorCause: boolean,\n): Event {\n if (!hint.originalException || !isError(hint.originalException)) {\n return event;\n }\n const exceptionName = (hint.originalException as ExtendedError).name || hint.originalException.constructor.name;\n\n const errorData = _extractErrorData(hint.originalException as ExtendedError, captureErrorCause);\n\n if (errorData) {\n const contexts: Contexts = {\n ...event.contexts,\n };\n\n const normalizedErrorData = normalize(errorData, depth);\n\n if (isPlainObject(normalizedErrorData)) {\n // We mark the error data as \"already normalized\" here, because we don't want other normalization procedures to\n // potentially truncate the data we just already normalized, with a certain depth setting.\n addNonEnumerableProperty(normalizedErrorData, '__sentry_skip_normalization__', true);\n contexts[exceptionName] = normalizedErrorData;\n }\n\n return {\n ...event,\n contexts,\n };\n }\n\n return event;\n}\n\n/**\n * Extract extra information from the Error object\n */\nfunction _extractErrorData(error: ExtendedError, captureErrorCause: boolean): Record<string, unknown> | null {\n // We are trying to enhance already existing event, so no harm done if it won't succeed\n try {\n const nativeKeys = [\n 'name',\n 'message',\n 'stack',\n 'line',\n 'column',\n 'fileName',\n 'lineNumber',\n 'columnNumber',\n 'toJSON',\n ];\n\n const extraErrorInfo: Record<string, unknown> = {};\n\n // We want only enumerable properties, thus `getOwnPropertyNames` is redundant here, as we filter keys anyway.\n for (const key of Object.keys(error)) {\n if (nativeKeys.indexOf(key) !== -1) {\n continue;\n }\n const value = error[key];\n extraErrorInfo[key] = isError(value) ? value.toString() : value;\n }\n\n // Error.cause is a standard property that is