From 90a9ca0319d658b2bc59c734bb086abf6aaa201d Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 18 Jul 2020 12:00:55 +0530 Subject: [PATCH] feat: add MergeError calss --- packages/webpack-cli/lib/groups/ConfigGroup.js | 5 ++--- packages/webpack-cli/lib/utils/errors/MergeError.js | 10 ++++++++++ test/merge/config-absent/merge-config-absent.test.js | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 packages/webpack-cli/lib/utils/errors/MergeError.js diff --git a/packages/webpack-cli/lib/groups/ConfigGroup.js b/packages/webpack-cli/lib/groups/ConfigGroup.js index b4750e01333..2b1c15ecd23 100644 --- a/packages/webpack-cli/lib/groups/ConfigGroup.js +++ b/packages/webpack-cli/lib/groups/ConfigGroup.js @@ -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 @@ -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); diff --git a/packages/webpack-cli/lib/utils/errors/MergeError.js b/packages/webpack-cli/lib/utils/errors/MergeError.js new file mode 100644 index 00000000000..74c39efd6e6 --- /dev/null +++ b/packages/webpack-cli/lib/utils/errors/MergeError.js @@ -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; diff --git a/test/merge/config-absent/merge-config-absent.test.js b/test/merge/config-absent/merge-config-absent.test.js index c6087390d1e..2bf2c57a729 100644 --- a/test/merge/config-absent/merge-config-absent.test.js +++ b/test/merge/config-absent/merge-config-absent.test.js @@ -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