Skip to content
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

#3354: Annotate when exceptions are caught but ignored #3356

Merged
merged 7 commits into from May 1, 2018
8 changes: 4 additions & 4 deletions bin/options.js
Expand Up @@ -30,8 +30,8 @@ function getOptions() {
: process.argv[process.argv.indexOf('--opts') + 1];

try {
const opts = fs
.readFileSync(optsPath, 'utf8')
// prettier-ignore
const opts = fs.readFileSync(optsPath, 'utf8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you ignore prettier here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the first function call is to fs.readFileSync(); there is no good reason to split the module from the function call -- not to mention it looks stupid. The rest of the chain processes its result via various FP methods (indented as expected for chained methods).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also like that no splitting the module and function call.
However, I believe that we should minimalize inline ignore because we decided to follow Prettier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the formatting of this code is more important than its readability, then I'll take it out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please take it out, thanks

.replace(/\\\s/g, '%20')
.split(/\s/)
.filter(Boolean)
Expand All @@ -40,8 +40,8 @@ function getOptions() {
process.argv = process.argv
.slice(0, 2)
.concat(opts.concat(process.argv.slice(2)));
} catch (err) {
// ignore
} catch (ignore) {
// NOTE: should console.error() and throw the error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you mean by this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly what it says. Believe it's a shortcoming of existing code. If anything goes wrong parsing the "mocha.opts" file or splicing its pieces/parts back into the cmdline arguments, the error is silently discarded. This just seems wrong, so I made a note; figured it should at least be discussed (and hopefully fixed in different issue).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plroebuck I got it. Thank you for the explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You concur about throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if an error occurs in the above, should that environment variable be set (L47)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we should be emitting a warning here, at minimum--unless there's some Git or issue history that makes me think otherwise.

That env var should be set anyway, because it's only used to check whether or not getOptions() should be called.

But that's another issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

}

process.env.LOADED_MOCHA_OPTS = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/progress.js
Expand Up @@ -112,7 +112,7 @@ Progress.prototype.draw = function(ctx) {
var w = ctx.measureText(text).width;

ctx.fillText(text, x - w / 2 + 1, y + fontSize / 2 - 1);
} catch (err) {
} catch (ignore) {
// don't fail if we can't render progress
}
return this;
Expand Down
2 changes: 1 addition & 1 deletion lib/runner.js
Expand Up @@ -244,7 +244,7 @@ Runner.prototype.fail = function(test, err) {
try {
err.stack =
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
} catch (ignored) {
} catch (ignore) {
// some environments do not take kindly to monkeying with the stack
}

Expand Down
4 changes: 2 additions & 2 deletions test/node-unit/file-utils.spec.js
Expand Up @@ -20,8 +20,8 @@ describe('file utils', function() {
try {
fs.symlinkSync(tmpFile('mocha-utils.js'), tmpFile('mocha-utils-link.js'));
symlinkSupported = true;
} catch (ignored) {
// ignored
} catch (ignore) {
// determine if file symlinks are supported
} finally {
removeTempDir();
}
Expand Down