Skip to content

Commit 04711c2

Browse files
authored
fix(vue): Remove logError from vueIntegration (#14958)
Removes `logError` and always re-throws the error when it's not handled by the user. PR for v8 (without removing `logError`): #14943 Logging the error has been a problem in the past already (see #7310). By just re-throwing the error we don't mess around with the initial message and stacktrace.
1 parent 1766d4c commit 04711c2

File tree

6 files changed

+71
-177
lines changed

6 files changed

+71
-177
lines changed

dev-packages/e2e-tests/test-applications/vue-3/tests/errors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
1919
type: 'Error',
2020
value: 'This is a Vue test error',
2121
mechanism: {
22-
type: 'generic',
22+
type: 'vue',
2323
handled: false,
2424
},
2525
},
@@ -47,7 +47,7 @@ test('sends an error with a parameterized transaction name', async ({ page }) =>
4747
type: 'Error',
4848
value: 'This is a Vue test error',
4949
mechanism: {
50-
type: 'generic',
50+
type: 'vue',
5151
handled: false,
5252
},
5353
},

docs/migration/v8-to-v9.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ The following changes are unlikely to affect users of the SDK. They are listed h
219219
});
220220
```
221221

222+
- The option `logErrors` in the `vueIntegration` has been removed. The Sentry Vue error handler will propagate the error to a user-defined error handler
223+
or just re-throw the error (which will log the error without modifying).
224+
222225
## 5. Build Changes
223226

224227
Previously the CJS versions of the SDK code (wrongfully) contained compatibility statements for default exports in ESM:
@@ -375,6 +378,9 @@ The Sentry metrics beta has ended and the metrics API has been removed from the
375378
});
376379
```
377380

381+
- Deprecated `logErrors` in the `vueIntegration`. The Sentry Vue error handler will propagate the error to a user-defined error handler
382+
or just re-throw the error (which will log the error without modifying).
383+
378384
## `@sentry/nuxt` and `@sentry/vue`
379385

380386
- When component tracking is enabled, "update" spans are no longer created by default.

packages/vue/src/errorhandler.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { captureException, consoleSandbox } from '@sentry/core';
1+
import { captureException } from '@sentry/core';
22
import type { ViewModel, Vue, VueOptions } from './types';
33
import { formatComponentName, generateComponentTrace } from './vendor/components';
44

55
type UnknownFunc = (...args: unknown[]) => void;
66

77
export const attachErrorHandler = (app: Vue, options: VueOptions): void => {
8-
const { errorHandler: originalErrorHandler, warnHandler, silent } = app.config;
8+
const { errorHandler: originalErrorHandler } = app.config;
99

1010
app.config.errorHandler = (error: Error, vm: ViewModel, lifecycleHook: string): void => {
1111
const componentName = formatComponentName(vm, false);
@@ -30,27 +30,15 @@ export const attachErrorHandler = (app: Vue, options: VueOptions): void => {
3030
setTimeout(() => {
3131
captureException(error, {
3232
captureContext: { contexts: { vue: metadata } },
33-
mechanism: { handled: false },
33+
mechanism: { handled: !!originalErrorHandler, type: 'vue' },
3434
});
3535
});
3636

3737
// Check if the current `app.config.errorHandler` is explicitly set by the user before calling it.
3838
if (typeof originalErrorHandler === 'function' && app.config.errorHandler) {
3939
(originalErrorHandler as UnknownFunc).call(app, error, vm, lifecycleHook);
40-
}
41-
42-
if (options.logErrors) {
43-
const hasConsole = typeof console !== 'undefined';
44-
const message = `Error in ${lifecycleHook}: "${error?.toString()}"`;
45-
46-
if (warnHandler) {
47-
(warnHandler as UnknownFunc).call(null, message, vm, trace);
48-
} else if (hasConsole && !silent) {
49-
consoleSandbox(() => {
50-
// eslint-disable-next-line no-console
51-
console.error(`[Vue warn]: ${message}${trace}`);
52-
});
53-
}
40+
} else {
41+
throw error;
5442
}
5543
};
5644
};

packages/vue/src/integration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const globalWithVue = GLOBAL_OBJ as typeof GLOBAL_OBJ & { Vue: Vue };
1010
const DEFAULT_CONFIG: VueOptions = {
1111
Vue: globalWithVue.Vue,
1212
attachProps: true,
13-
logErrors: true,
1413
attachErrorHandler: true,
1514
tracingOptions: {
1615
hooks: DEFAULT_HOOKS,

packages/vue/src/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ export interface VueOptions {
4141
*/
4242
attachProps: boolean;
4343

44-
/**
45-
* When set to `true`, original Vue's `logError` will be called as well.
46-
* https://github.com/vuejs/vue/blob/c2b1cfe9ccd08835f2d99f6ce60f67b4de55187f/src/core/util/error.js#L38-L48
47-
*/
48-
logErrors: boolean;
49-
5044
/**
5145
* By default, Sentry attaches an error handler to capture exceptions and report them to Sentry.
5246
* When `attachErrorHandler` is set to `false`, automatic error reporting is disabled.

0 commit comments

Comments
 (0)