Skip to content

Commit

Permalink
Use type-check to throw error instead of a broad try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinika committed Nov 28, 2024
1 parent 28c801c commit b71034e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/cli/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,18 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
// 4. we can then reapply the values after yargs-parser is done.
const nodeArgs = (Array.isArray(args) ? args : args.split(' ')).reduce(
(acc, arg) => {
try {
const pair = arg.split('=');
let flag = pair[0];
if (isNodeFlag(flag, false)) {
flag = flag.replace(/^--?/, '');
return arg.includes('=')
? acc.concat([[flag, pair[1]]])
: acc.concat([[flag, true]]);
}
return acc;
} catch (err) {
if (typeof arg !== 'string') {
throw new Error(`Invalid option ${arg} passed to mocha cli`);
}
const pair = arg.split('=');
let flag = pair[0];
if (isNodeFlag(flag, false)) {
flag = flag.replace(/^--?/, '');
return arg.includes('=')
? acc.concat([[flag, pair[1]]])
: acc.concat([[flag, true]]);
}
return acc;
},
[]
);
Expand Down Expand Up @@ -196,7 +195,8 @@ const loadPkgRc = (args = {}) => {
filepath
);
} else {
debug('failed to read default package.json at %s; ignoring', filepath);
debug('failed to read default package.json at %s; ignoring',
filepath);
return result;
}
}
Expand Down

0 comments on commit b71034e

Please sign in to comment.