Line data Source code
1 : import type { ErrorEvent } from '@sentry/vue'
2 :
3 2356 : const UNKNOWN_COMMAND = /^Command .* not found$/s
4 : const COMMAND_STORE_FRAME_DEPTH = 2
5 :
6 0 : function isCalledFromEvaluatedCode(event: ErrorEvent): boolean {
7 0 : const exception = event.exception?.values?.at(-1)
8 0 : if (!UNKNOWN_COMMAND.test(exception?.value ?? '')) return false
9 :
10 0 : const caller = exception?.stacktrace?.frames?.at(
11 : -(COMMAND_STORE_FRAME_DEPTH + 1)
12 : )
13 0 : return caller?.filename === '<anonymous>' && caller.lineno !== undefined
14 : }
15 :
16 0 : export function tagSentryEvaluatedCommandCaller(event: ErrorEvent): ErrorEvent {
17 0 : if (!isCalledFromEvaluatedCode(event)) return event
18 0 : return { ...event, tags: { ...event.tags, error_origin: 'third_party' } }
19 : }
|