Default error handler should not catch error in PROD when happening in an async function
Vue version
3.2.47
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-guvjj7?file=src/main.js
Steps to reproduce
Throw an error in an async function triggered in a vue component (SFC playground has a special errorCaptured hook, so this is why I'm using Stackblitz)
Change vue PROD/DEV mode in Stackblitz with:
"scripts": {
"dev": "NODE_ENV=production|development vite",
.....
}
What is expected?
Error thrown in async code won't crash the application so in my opinion Vue should not catch these and let them propagate (up to uncaughtexception
handler). Since this behaviour is not consistent between prod and dev, this is a bit counter-intuitive. I know popular error tracking SDK offer built-in implementations for Vue, but a lot of tools are instrumenting the uncaughtexception
handler.
What is actually happening?
Here https://github.com/vuejs/core/blob/main/packages/runtime-core/src/errorHandling.ts#L164, in production mode errors are caught and simply logged to the console.log, so runtime errors are less disruptive
in DEV the error is thrown
in PROD (`NODE_ENV=production vite ) the error is not thrown, just logged
System Info
No response
Any additional comments?
Workaround is to use the error captured handler https://vuejs.org/api/application.html#app-config-errorhandler
NB: Just my 2cents, but to open up the discussion: catching the error on production even for synchronous code is a lot of handholding, I'm wondering if the default behaviour should be let the error be thrown. I understand the idea of being less disruptive for potential issues but at the same time it's giving away some power for developers that are relying on default error behaviour.