10000 Custom error handler causing recursive error handling leading to Maximum call stack size exceeded error · Issue #13241 · vuejs/vue · GitHub
[go: up one dir, main page]

Skip to content

Custom error handler causing recursive error handling leading to Maximum call stack size exceeded error #13241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adamreisnz opened this issue Mar 14, 2025 · 1 comment

Comments

@adamreisnz
Copy link

Looking at the code for callWithErrorHandling, it has a try/catch block which will call handleError when an error occurs.

However, handleError will then try to process the error with callWithErrorHandling again, which leads to infinite recursion, causing RangeError Maximum call stack size exceeded.

Image

Aside from making sure the custom error handler doesn't ever throw any errors, can we maybe prevent within Vue that callWithErrorHandling will not be called again recursively if it itself has errored?

@steffencrespo
Copy link

Thanks for reporting this — I agree this can easily lead to subtle infinite recursion, especially when user-defined global error handlers introduce unexpected behavior (or even just logging tools that throw).

One possible approach to mitigating this could be to track an internal flag during callWithErrorHandling, for example:

let isHandlingError = false;

function callWithErrorHandling(fn) {
  if (isHandlingError) {
    // avoiding recursive calls
    return;
  }
  try {
    fn();
  } catch (err) {
    isHandlingError = true;
    try {
      handleError(err);
    } finally {
      isHandlingError = false;
    }
  }
}

This is a common pattern to prevent re-entrancy in error-handling code, and I believe it could help prevent stack overflows without interfering with normal error propagation.

You should still ensure that yuor custom error handlers are resilient and don't throw — but safeguarding at the framework level could improve developer experience significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0