-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
🐛 Bug: Reports the Error twice when its message contains something similar to a stack #3992
Comments
Sorry nobody replied sooner. Just tried this on mocha v7 on a mac and got the expected
I believe this is now resolved in latest. |
Indeed, thanks a lot 👍 |
@craigtaub While it works for the two examples above, I still have an issue when the message contained into the error looks like a stacktrace, here is an example of the issue: function oupsStackStack() {
const err = new Error();
throw new Error(`An error occured with following trace:\n\n${err.stack}`);
}
describe("describe", () => {
it("it oupsStackStack", () => {
oupsStackStack();
});
}); If you run this snippet with Mocha 7.2.0, you should see the error message When I ran it, the reported error was the following (with mocha 7.2.0):
While I would have expected something like:
|
Ah I see, so the message is
So should print that then the call stack. Odd. Not sure its a big issue but certainly seems odd. Ran this as a normal node script and printed what submitter has suggested it should. Assuming a bug or at least needs further investigation. |
Confirmed that the snippet in #3992 (comment) gives the duplicate error stack still. |
Given mocha properly handles errors with cause, I believe the recommended approach would be to use it instead of copying the stack in the message. I updated my library (fast-check) to switch to error with cause (will be the default starting at v4). |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Mocha reports twice the
Error
instance when it contains something that looks similar to a stacktrace.As a consequence
throw new Error("Oups.");
andthrow new Error("Oups. at plouf (C:\\dev\\try-mocha\\test.js:9:15)");
will not be treated the same way in the report of Mocha.Steps to Reproduce
Here is a small spec file to reproduce:
Error related to dubzzz/fast-check#399
Expected behavior: [What you expect to happen]
The reports of
oups
andoupsStack
should be similar (even if oupsStack contains something similar to a stack trace).I would have expected the following error report from mocha:
Actual behavior: [What actually happens]
Here is the actual report I got from Mocha:
We can see that
Oups. at plouf
is visible twice in the log whileOups.
is only visible once.Reproduces how often: [What percentage of the time does it reproduce?]
Versions
mocha --version
andnode node_modules/.bin/mocha --version
:mocha --version
: nonenode_modules/.bin/mocha --version
: 6.2.0node --version
: 12.6.0The text was updated successfully, but these errors were encountered: