Skip to content

Commit

Permalink
feat: add MergeError calss
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Jul 18, 2020
1 parent a875a61 commit 90a9ca0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { extensions } = require('interpret');
const webpackMerge = require('webpack-merge');
const GroupHelper = require('../utils/GroupHelper');
const rechoir = require('rechoir');
const logger = require('../utils/logger');
const MergeError = require('../utils/errors/MergeError');

// Order defines the priority, in increasing order
// example - config file lookup will be in order of .webpack/webpack.config.development.js -> webpack.config.development.js -> webpack.config.js
Expand Down Expand Up @@ -174,8 +174,7 @@ class ConfigGroup extends GroupHelper {
const newConfigPath = this.resolveFilePath(merge);

if (!newConfigPath) {
logger.error("The supplied merge config doesn't exist.");
process.exit(1);
throw new MergeError("The supplied merge config doesn't exist.");
}

const configFiles = getConfigInfoFromFileName(newConfigPath);
Expand Down
10 changes: 10 additions & 0 deletions packages/webpack-cli/lib/utils/errors/MergeError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class MergeError extends Error {
constructor(message) {
super(message);
this.name = 'MergeError';
// No need to show stack trace for known errors
this.stack = '';
}
}

module.exports = MergeError;
2 changes: 1 addition & 1 deletion test/merge/config-absent/merge-config-absent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('merge flag configuration', () => {
// Since the process will exit, nothing on stdout
expect(stdout).toBeFalsy();
// Confirm that the user is notified
expect(stderr).toContain(`[webpack-cli] The supplied merge config doesn't exist.`);
expect(stderr).toContain(`MergeError: The supplied merge config doesn't exist.`);
// Default config would be used
expect(fs.existsSync(join(__dirname, './dist/merged.js'))).toBeFalsy();
// Since the process will exit so no compilation will be done
Expand Down

0 comments on commit 90a9ca0

Please sign in to comment.