-
-
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: mocha fails silently on invalid package.json
section
#5141
Comments
🤔 I don't reproduce this in https://github.com/mochajs/mocha-examples/tree/4b00891d6c7886f2d451e962a974478e7d3c1aa9/packages/hello-world. After adding an invalid
Could you post a standalone reproduction please @dhdaines? |
Relevant piece of code in mocha: Lines 182 to 201 in c44653a
If one hasn't specified a @JoshuaKGoldberg Your error might be from npm itself |
Ah. I suppose the author of the code simply didn't bother distinguishing a non-existent |
Hi maintainers! Thank you for all your hard work, but I don't understand your process for PRs, it seems that you have to mark this issue as "accepting-prs" before I can submit one? As you can see above I have fixed the bug. Please let me know when I can make a PR, thanks again! |
We're discussing if we should drop that
It does actually: const filepath = args.package || findUp.sync(mocharc.package);
if (filepath) { I think its rather a case of opting between the least bad of two options:
For those that have options in their |
Ah, I understand. I would be inclined to think that if your Perhaps the debug log message could be changed to a warning? |
Repeating from #5141 (comment) 🙂: Could you post a standalone reproduction please @dhdaines? (or anybody else?)
We can't accept a PR unless we fully understand the problem. We can't fully understand the problem unless we can reproduce it. And I haven't figured out how to reproduce it. Hence the For anybody reading this wondering why I'm being such a stickler (😅): https://antfu.me/posts/why-reproductions-are-required is a big deep dive into it. https://antfu.me/posts/why-reproductions-are-required#how-to-create-a-minimal-reproduction specifically talks about a minimum reproduction, which is what I'm asking for here. |
Ah okay! I didn't realize that's what "waiting for author" meant. Happy to provide a reproduction, will do so in the next few minutes. |
Here you go. Note that it clarifies the NPM error you got above, which comes from NPM. You have to run |
Aha! Thanks, that's exactly what I was looking for. Perfect. Agreed on the bug, this is definitely an edge case Mocha should handle better as you've described. 🚀 accepting pull requests! |
Thank you and sorry for the confusion! |
I like this suggestion. Something warning that the package.gain could not be checked for config (ensuring it only triggers if there’s no other config found either) |
* fix: report syntax errors in package.json (fixes: #5141) * fix(tests): incorrect test (should use existing result) Since `readFileSync` is only stubbed `onFirstCall` we get a different answer the second time around which is probably Not What You Want. But also we *already checked that config = false*. So you could just remove this test, it does nothing useful. * fix: separate read and parse errors * fix: clarify invalid JSON Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com> * fix(test): expect only a SyntaxError nothing else --------- Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Bug Report Checklist
faq
label, but none matched my issue.Expected
I made an error in my
package.json
(an extra comma) because JSON is a bad format for configuration files ;-) like this:I expected
mocha
to give me an error, ideally a bit friendlier than the one fromnpm
, but something like that:Actual
Mocha just failed as if I hadn't configured it at all. This was very confusing:
Minimal, Reproducible Example
See "expected" above but basically:
then add the offending section to
package.json
, then createfoo.spec.js
, then try to runmocha
.Versions
10.4.0 10.4.0 v20.11.0
Additional Info
I could definitely provide a PR if you could direct me to the appropriate place in the code (with which I am not familiar)
The text was updated successfully, but these errors were encountered: