Skip to content

Commit

Permalink
fix(vue): Re-throw error when no errorHandler exists
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gr1d committed Jan 9, 2025
1 parent 785aab3 commit a6459e2
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 143 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-errorHandler',
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-errorHandler',
handled: false,
},
},
Expand Down
14 changes: 10 additions & 4 deletions packages/vue/src/errorhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ export const attachErrorHandler = (app: Vue, options: VueOptions): void => {
setTimeout(() => {
captureException(error, {
captureContext: { contexts: { vue: metadata } },
mechanism: { handled: false },
mechanism: { handled: !!originalErrorHandler, type: 'vue-errorHandler' },
});
});

// 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) {
} // TODO(v9): Always throw when no user-defined error handler is provided (this will log the error to the console as well). Delete the Code with logErrors below
/* else {
throw error;
} */

if (!originalErrorHandler) {
throw error;
// eslint-disable-next-line deprecation/deprecation
} else if (options.logErrors) {
const hasConsole = typeof console !== 'undefined';
const message = `Error in ${lifecycleHook}: "${error && error.toString()}"`;

Expand Down
2 changes: 2 additions & 0 deletions packages/vue/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface VueOptions {
/**
* 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
*
* @deprecated Will be removed in future versions of the SDK. The error will always be logged unless you define a custom Vue errorHandler.
*/
logErrors: boolean;

Expand Down
Loading

0 comments on commit a6459e2

Please sign in to comment.