Skip to content

Commit

Permalink
feature: log options validations errors in CLI
Browse files Browse the repository at this point in the history
Ajv is using doT to compile validation logic. There is minimal overhead validating an object against a pre-compiled schema. In case of the CLI, options will be validated once by the CLI engine and the second time by API.

I prefer to explicitly handle error checking rather than relying on an error getting thrown by the API engine.

API needs to retain “validationErrors” object nevertheless to enable debugging when using webpack programmatically.
  • Loading branch information
gajus committed Sep 9, 2016
1 parent ad95343 commit efc4113
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fs.existsSync = fs.existsSync || path.existsSync;
var resolve = require("enhanced-resolve");
var interpret = require("interpret");
var WebpackOptionsDefaulter = require("../lib/WebpackOptionsDefaulter");
var validateWebpackOptions = require("../lib/validateWebpackOptions");

module.exports = function(optimist, argv, convertOptions) {

Expand Down Expand Up @@ -553,5 +554,11 @@ module.exports = function(optimist, argv, convertOptions) {
console.error("Use --help to display the CLI options.");
process.exit(-1); // eslint-disable-line
}
var webpackOptionsValidationErrors = validateWebpackOptions(options);

if (webpackOptionsValidationErrors.length) {
console.error("Configuration is invalid. Fix the following errors:", webpackOptionsValidationErrors);
process.exit(-1); // eslint-disable-line
}
}
};

0 comments on commit efc4113

Please sign in to comment.