Skip to content

Commit

Permalink
fix(vue): Remove logError from vueIntegration (#14958)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
s1gr1d authored Jan 10, 2025
1 parent 1766d4c commit 04711c2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sends an error', async ({ page }) => {
type: 'Error',
value: 'This is a Vue test error',
mechanism: {
type: 'generic',
type: 'vue',
handled: false,
},
},
Expand Down Expand Up @@ -47,7 +47,7 @@ test('sends an error with a parameterized transaction name', async ({ page }) =>
type: 'Error',
value: 'This is a Vue test error',
mechanism: {
type: 'generic',
type: 'vue',
handled: false,
},
},
Expand Down
6 changes: 6 additions & 0 deletions docs/migration/v8-to-v9.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ The following changes are unlikely to affect users of the SDK. They are listed h
});
```

- The option `logErrors` in the `vueIntegration` has been removed. The Sentry Vue error handler will propagate the error to a user-defined error handler
or just re-throw the error (which will log the error without modifying).

## 5. Build Changes

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

- Deprecated `logErrors` in the `vueIntegration`. The Sentry Vue error handler will propagate the error to a user-defined error handler
or just re-throw the error (which will log the error without modifying).

## `@sentry/nuxt` and `@sentry/vue`

- When component tracking is enabled, "update" spans are no longer created by default.
Expand Down
22 changes: 5 additions & 17 deletions packages/vue/src/errorhandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { captureException, consoleSandbox } from '@sentry/core';
import { captureException } from '@sentry/core';
import type { ViewModel, Vue, VueOptions } from './types';
import { formatComponentName, generateComponentTrace } from './vendor/components';

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

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

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

// Check if the current `app.config.errorHandler` is explicitly set by the user before calling it.
if (typeof originalErrorHandler === 'function' && app.config.errorHandler) {
(originalErrorHandler as UnknownFunc).call(app, error, vm, lifecycleHook);
}

if (options.logErrors) {
const hasConsole = typeof console !== 'undefined';
const message = `Error in ${lifecycleHook}: "${error?.toString()}"`;

if (warnHandler) {
(warnHandler as UnknownFunc).call(null, message, vm, trace);
} else if (hasConsole && !silent) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.error(`[Vue warn]: ${message}${trace}`);
});
}
} else {
throw error;
}
};
};
1 change: 0 additions & 1 deletion packages/vue/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const globalWithVue = GLOBAL_OBJ as typeof GLOBAL_OBJ & { Vue: Vue };
const DEFAULT_CONFIG: VueOptions = {
Vue: globalWithVue.Vue,
attachProps: true,
logErrors: true,
attachErrorHandler: true,
tracingOptions: {
hooks: DEFAULT_HOOKS,
Expand Down
6 changes: 0 additions & 6 deletions packages/vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ export interface VueOptions {
*/
attachProps: boolean;

/**
* When set to `true`, original Vue's `logError` will be called as well.
* https://github.com/vuejs/vue/blob/c2b1cfe9ccd08835f2d99f6ce60f67b4de55187f/src/core/util/error.js#L38-L48
*/
logErrors: boolean;

/**
* By default, Sentry attaches an error handler to capture exceptions and report them to Sentry.
* When `attachErrorHandler` is set to `false`, automatic error reporting is disabled.
Expand Down
Loading

0 comments on commit 04711c2

Please # to comment.