Skip to content

Commit

Permalink
refactor(index): concat invalid args provided into error object
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Nov 10, 2020
1 parent 094627d commit 12a5c04
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const platform = os.platform();
function parseOptions(acceptedOptions, options) {
return new Promise((resolve, reject) => {
const args = [];
const invalidArgs = [];
Object.keys(options).forEach((key) => {
if (Object.prototype.hasOwnProperty.call(acceptedOptions, key)) {
// eslint-disable-next-line valid-typeof
Expand All @@ -25,19 +26,21 @@ function parseOptions(acceptedOptions, options) {
args.push(options[key]);
}
} else {
reject(
new Error(
`Invalid value type provided for option '${key}', expected ${
acceptedOptions[key].type
} but recieved ${typeof options[key]}`
)
invalidArgs.push(
`Invalid value type provided for option '${key}', expected ${
acceptedOptions[key].type
} but recieved ${typeof options[key]}`
);
}
} else {
reject(new Error(`Invalid option provided '${key}'`));
invalidArgs.push(`Invalid option provided '${key}'`);
}
});
resolve(args);
if (invalidArgs.length === 0) {
resolve(args);
} else {
reject(new Error(invalidArgs.join('; ')));
}
});
}

Expand Down

0 comments on commit 12a5c04

Please sign in to comment.