-
-
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
Do not silently fail on bad opts argument #2716
Conversation
Ah, missed the tests. If we want to cover that |
(DISCLAIMER: the following is a thought on an impression after taking one look at the change and not thoroughly investigating the code. It would need at least as much review as the PR itself.) Could this be equivalently fixed by removing the try-catch altogether and replacing it with only executing the contents of the |
Re. tests -- that file does look like it's the place where commandline arguments (of which |
I see what you mean, I do tend to steer clear of try/catch blocks in my own work. Figured though that for my first PR for a big project like mocha I should keep it adhering to what's already there haha. I can certainly try my hand at dropping the try/catch if consensus agrees that's the way to go. In which case, how far down in Node versions does Mocha support? Asking so I know what modern JS I can('t) use. |
@mochajs/core Any opinions on try-catch here? Re. Node versions, I believe we're testing all the supported versions on Travis (so... looks like Node 0.10?), if I recall correct. |
I agree with @ScottFreeCode; let's just let it throw. |
var optsPath = optsIndex === -1 | ||
? defaultPath | ||
: process.argv[optsIndex + 1]; | ||
var shouldThrowError = optsIndex !== -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename this to wasOptsProvided
. It makes the code / reasoning more clearer imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind the feedback in case the variable is no longer necessary.
@ScottFreeCode @boneskull Yeah, but how do you check if the file exists otherwise? (to get the default one, if it exists). |
Hmm... according to the docs: "Note that |
you can use |
So, |
@ScottFreeCode ...apparently? Either way, checking file existence is usually an anti-pattern |
Usually; although using try-catch for program logic rather than just error handling is also an antipattern unless there's no good alternative... I guess it comes down to whether we're more concerned by the race condition that the file could be deleted in the split instant between the existence check and the attempt to use it, resulting in a clear error that doesn't recur on subsequent runs, or by the risk that we screw up the try-catch handling, resulting in things like this issue about errors being silently (!) suppressed that should not have been suppressed at all. |
I am a bot that watches issues for inactivity. |
For #2576.