From 68b3596abab8aa6c61c702121a733181884f3ad5 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Thu, 26 Apr 2018 09:48:53 -0500 Subject: [PATCH 1/4] style(*various*): Annotate when exceptions are caught but ignored There's an existing convertion to name intentionally ignored errors in catch block as `ignore`. Modified codebase to follow it. Fixes #3354 --- bin/options.js | 7 +++---- lib/browser/progress.js | 2 +- lib/runner.js | 2 +- test/node-unit/file-utils.spec.js | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bin/options.js b/bin/options.js index 41f7222a62..651fbf047c 100644 --- a/bin/options.js +++ b/bin/options.js @@ -30,8 +30,7 @@ function getOptions() { : process.argv[process.argv.indexOf('--opts') + 1]; try { - const opts = fs - .readFileSync(optsPath, 'utf8') + const opts = fs.readFileSync(optsPath, 'utf8') .replace(/\\\s/g, '%20') .split(/\s/) .filter(Boolean) @@ -40,8 +39,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 } process.env.LOADED_MOCHA_OPTS = true; diff --git a/lib/browser/progress.js b/lib/browser/progress.js index 0dcb341898..7bf400b58e 100644 --- a/lib/browser/progress.js +++ b/lib/browser/progress.js @@ -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; diff --git a/lib/runner.js b/lib/runner.js index 565d47d6e5..7ada7d1411 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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 } diff --git a/test/node-unit/file-utils.spec.js b/test/node-unit/file-utils.spec.js index 93aab88b4a..e4ba451b69 100644 --- a/test/node-unit/file-utils.spec.js +++ b/test/node-unit/file-utils.spec.js @@ -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(); } From eb034dd81efbeb61c7378d085a4983a93ce45998 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Thu, 26 Apr 2018 10:24:21 -0500 Subject: [PATCH 2/4] style(bin/options.js): Turn off prettier for single line Prettier reformatting is just wrong here. fs.readFileSync() should **not** be split across multiple lines. --- bin/options.js | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/options.js b/bin/options.js index 651fbf047c..e70030227f 100644 --- a/bin/options.js +++ b/bin/options.js @@ -30,6 +30,7 @@ function getOptions() { : process.argv[process.argv.indexOf('--opts') + 1]; try { + // prettier-ignore const opts = fs.readFileSync(optsPath, 'utf8') .replace(/\\\s/g, '%20') .split(/\s/) From 62be9189faf5feaa30afd837e41186d4275fc0e9 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 28 Apr 2018 09:23:27 -0500 Subject: [PATCH 3/4] Revert "style(bin/options.js): Turn off prettier for single line" This reverts commit eb034dd81efbeb61c7378d085a4983a93ce45998. --- bin/options.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/options.js b/bin/options.js index e70030227f..651fbf047c 100644 --- a/bin/options.js +++ b/bin/options.js @@ -30,7 +30,6 @@ function getOptions() { : process.argv[process.argv.indexOf('--opts') + 1]; try { - // prettier-ignore const opts = fs.readFileSync(optsPath, 'utf8') .replace(/\\\s/g, '%20') .split(/\s/) From 792b340c12abbb010f0f2af7464c786698c00d75 Mon Sep 17 00:00:00 2001 From: Paul Roebuck Date: Sat, 28 Apr 2018 09:35:52 -0500 Subject: [PATCH 4/4] style(bin/options.js): Revert un-Prettier comment per Boneskull's request --- bin/options.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/options.js b/bin/options.js index 651fbf047c..60cbcd705e 100644 --- a/bin/options.js +++ b/bin/options.js @@ -30,7 +30,8 @@ function getOptions() { : process.argv[process.argv.indexOf('--opts') + 1]; try { - const opts = fs.readFileSync(optsPath, 'utf8') + const opts = fs + .readFileSync(optsPath, 'utf8') .replace(/\\\s/g, '%20') .split(/\s/) .filter(Boolean)