-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
feat(runtime-core): expose exception if app.errorHandler throws exception #987
Conversation
If you expect it to just throw, what's the point of adding |
I don't think we should expose the exception - this would cause any error in the error handler to crash the app, which defeats the purpose of having an error handler. |
The reason is to expose the place where the exception happen, not exposing the exception will make the test pass but to log the exception. import { createApp } from "vue";
describe("test", () => {
it("test", () => {
createApp({
setup() {
expect(1).toBe(2);
},
}).mount(document.createElement("div"));
});
}); Rethrowing the exception will make the error to be in the correct place: import { createApp } from "../utils";
describe("test", () => {
it("test", () => {
const app = createApp({
setup() {
expect(1).toBe(2);
},
});
app.config.errorHandler = (e) => {
throw e;
};
app.mount(document.createElement("div"));
});
}); That's the behaviour I would expect |
My point is in your test setup you don't need the |
It only throws during production, because I'm running my tests in The way I'm doing in v2, setup my tests for the composition API, without it I encounter the same issue as in v3 // jest.config.js
Vue.config.warnHandler = (err: any) => {
throw err;
}; if I do something similar in v3 I get: Maximum call stack size exceeded
Other way to put this PR is: I also check the logError method to see if there's any way to throw: Checked the code and the logError looks to have the //runtime-core.esm-bundler.js
function logError(err, type, contextVNode) {
// default behavior is crash in prod & test, recover in dev.
if ((process.env.NODE_ENV !== 'production') && ( !false)) {
// warn log
}
else {
throw err;
}
}
// runtime-core.cjs.js
// default behavior is crash in prod & test, recover in dev.
function logError(err, type, contextVNode) {
// default behavior is crash in prod & test, recover in dev.
{
const info = ErrorTypeStrings[type];
// warn log
}
} Not allowing it to throw, the only way is to run tests in production and use |
Problem
If any of
app.context.errorHandler
orapp.context.warnHandler
throws an exception it will call it self over and over.This behaviour is problematic specially when doing asserts in the setup, making the test to pass and the error to be obfuscated.
https://github.com/pikax/vue-composable/blob/vue3/packages/web/__tests__/utils.ts#L5-L23
jest log of the build, the file
broadcastChannel.spec.ts
should have tests failing, but they are passing and just logging error.