From 065ea675c3f868738cd156d061c0b79ded060c3e Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 29 Aug 2023 17:57:11 +0200 Subject: [PATCH 1/2] feat(vue): Mark errors caught from Vue wrappers as unhandled --- packages/vue/src/errorhandler.ts | 9 +++++++++ packages/vue/src/router.ts | 12 +++++++++++- packages/vue/test/router.test.ts | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/vue/src/errorhandler.ts b/packages/vue/src/errorhandler.ts index fd4a1d564343..542d341c322f 100644 --- a/packages/vue/src/errorhandler.ts +++ b/packages/vue/src/errorhandler.ts @@ -1,4 +1,5 @@ import { getCurrentHub } from '@sentry/browser'; +import { addExceptionMechanism } from '@sentry/utils'; import type { Options, ViewModel, Vue } from './types'; import { formatComponentName, generateComponentTrace } from './vendor/components'; @@ -31,6 +32,14 @@ export const attachErrorHandler = (app: Vue, options: Options): void => { setTimeout(() => { getCurrentHub().withScope(scope => { scope.setContext('vue', metadata); + + scope.addEventProcessor(event => { + addExceptionMechanism(event, { + handled: false, + }); + return event; + }); + getCurrentHub().captureException(error); }); }); diff --git a/packages/vue/src/router.ts b/packages/vue/src/router.ts index 25408f24f6b6..c5252dc92cee 100644 --- a/packages/vue/src/router.ts +++ b/packages/vue/src/router.ts @@ -2,6 +2,7 @@ import { captureException, WINDOW } from '@sentry/browser'; import type { Transaction, TransactionContext, TransactionSource } from '@sentry/types'; import { getActiveTransaction } from './tracing'; +import { addExceptionMechanism } from '@sentry/utils'; interface VueRouterInstrumationOptions { /** @@ -77,7 +78,16 @@ export function vueRouterInstrumentation( }); } - router.onError(error => captureException(error)); + router.onError(error => + captureException(error, scope => { + scope.addEventProcessor(event => { + addExceptionMechanism(event, { handled: false }); + return event; + }); + + return scope; + }), + ); router.beforeEach((to, from, next) => { // According to docs we could use `from === VueRouter.START_LOCATION` but I couldnt get it working for Vue 2 diff --git a/packages/vue/test/router.test.ts b/packages/vue/test/router.test.ts index 044228181f50..fdffb83631eb 100644 --- a/packages/vue/test/router.test.ts +++ b/packages/vue/test/router.test.ts @@ -72,7 +72,8 @@ describe('vueRouterInstrumentation()', () => { onErrorCallback(testError); expect(captureExceptionSpy).toHaveBeenCalledTimes(1); - expect(captureExceptionSpy).toHaveBeenCalledWith(testError); + // second function is the scope callback + expect(captureExceptionSpy).toHaveBeenCalledWith(testError, expect.any(Function)); }); it.each([ From 9099ebb37ec4ffcd7effa6945835aa71bb66750d Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 30 Aug 2023 11:45:53 +0200 Subject: [PATCH 2/2] lint --- packages/vue/src/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vue/src/router.ts b/packages/vue/src/router.ts index c5252dc92cee..3b3f7f285472 100644 --- a/packages/vue/src/router.ts +++ b/packages/vue/src/router.ts @@ -1,8 +1,8 @@ import { captureException, WINDOW } from '@sentry/browser'; import type { Transaction, TransactionContext, TransactionSource } from '@sentry/types'; +import { addExceptionMechanism } from '@sentry/utils'; import { getActiveTransaction } from './tracing'; -import { addExceptionMechanism } from '@sentry/utils'; interface VueRouterInstrumationOptions { /**