Skip to content

Commit 69c2f1a

Browse files
author
kingdaro
committed
refactor(removed plugin errors): use custom error class
1 parent 0d780b5 commit 69c2f1a

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎lib/RemovedPluginError.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = class RemovedPluginError extends Error {}

‎lib/webpack.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const WebpackOptionsDefaulter = require("./WebpackOptionsDefaulter");
1212
const validateSchema = require("./validateSchema");
1313
const WebpackOptionsValidationError = require("./WebpackOptionsValidationError");
1414
const webpackOptionsSchema = require("../schemas/WebpackOptions.json");
15+
const RemovedPluginError = require('./RemovedPluginError');
1516

1617
const webpack = (options, callback) => {
1718
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options);
@@ -138,7 +139,7 @@ const defineMissingPluginError = (namespace, pluginName, errorMessage) => {
138139
configurable: false,
139140
enumerable: true,
140141
get() {
141-
throw new Error(`RemovedPluginError: ${errorMessage}`);
142+
throw new RemovedPluginError(errorMessage);
142143
}
143144
});
144145
};
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const webpack = require("../../../../lib/webpack");
22
const should = require("should");
3+
const RemovedPluginError = require('../../../../lib/RemovedPluginError')
34

45
it("should error when accessing removed plugins", () => {
56
should.throws(
67
() => webpack.optimize.UglifyJsPlugin,
7-
Error,
8+
RemovedPluginError,
89
"webpack.optimize.UglifyJsPlugin has been removed, please use config.optimization.minimize instead."
910
);
1011

1112
should.throws(
1213
() => webpack.optimize.CommonsChunkPlugin,
13-
Error,
14+
RemovedPluginError,
1415
"webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead."
1516
);
1617
});

0 commit comments

Comments
 (0)