Skip to content

Commit fe375b9

Browse files
authored
feat(vue): Mark errors caught by Vue wrappers as unhandled (#8905)
Report exceptions caught by our Vue error handler and routing instrumentation as unhandled. Detailed write up in #8890
1 parent 726a6ad commit fe375b9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/vue/src/errorhandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getCurrentHub } from '@sentry/browser';
2+
import { addExceptionMechanism } from '@sentry/utils';
23

34
import type { Options, ViewModel, Vue } from './types';
45
import { formatComponentName, generateComponentTrace } from './vendor/components';
@@ -31,6 +32,14 @@ export const attachErrorHandler = (app: Vue, options: Options): void => {
3132
setTimeout(() => {
3233
getCurrentHub().withScope(scope => {
3334
scope.setContext('vue', metadata);
35+
36+
scope.addEventProcessor(event => {
37+
addExceptionMechanism(event, {
38+
handled: false,
39+
});
40+
return event;
41+
});
42+
3443
getCurrentHub().captureException(error);
3544
});
3645
});

packages/vue/src/router.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { captureException, WINDOW } from '@sentry/browser';
22
import type { Transaction, TransactionContext, TransactionSource } from '@sentry/types';
3+
import { addExceptionMechanism } from '@sentry/utils';
34

45
import { getActiveTransaction } from './tracing';
56

@@ -78,7 +79,16 @@ export function vueRouterInstrumentation(
7879
});
7980
}
8081

81-
router.onError(error => captureException(error));
82+
router.onError(error =>
83+
captureException(error, scope => {
84+
scope.addEventProcessor(event => {
85+
addExceptionMechanism(event, { handled: false });
86+
return event;
87+
});
88+
89+
return scope;
90+
}),
91+
);
8292

8393
router.beforeEach((to, from, next) => {
8494
// According to docs we could use `from === VueRouter.START_LOCATION` but I couldnt get it working for Vue 2

packages/vue/test/router.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ describe('vueRouterInstrumentation()', () => {
7272
onErrorCallback(testError);
7373

7474
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
75-
expect(captureExceptionSpy).toHaveBeenCalledWith(testError);
75+
// second function is the scope callback
76+
expect(captureExceptionSpy).toHaveBeenCalledWith(testError, expect.any(Function));
7677
});
7778

7879
it.each([

0 commit comments

Comments
 (0)