Custom error handler causing recursive error handling leading to Maximum call stack size exceeded error
Opened this issue · 1 comments
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.
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?
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.
