diff --git a/lib/pipeline/webpackProcess.js b/lib/pipeline/webpackProcess.js index d102567f..847c278f 100644 --- a/lib/pipeline/webpackProcess.js +++ b/lib/pipeline/webpackProcess.js @@ -6,6 +6,16 @@ const writeFile = require('util').promisify(require('fs').writeFile); let webpackProcess; +function errorMessage(e) { + if (typeof e === 'string') { + return e; + } else if (e && e.message) { + return e.message; + } else { + return e; + } +} + class WebpackProcess extends ProcessWrapper { constructor(options) { super(options); @@ -16,9 +26,7 @@ class WebpackProcess extends ProcessWrapper { try { await this.webpackRun(assets, importsList, callback); } catch (e) { - console.error(e.message); - callback(e); - // ?? should return e or e.message + callback(errorMessage(e)); } } @@ -33,9 +41,7 @@ class WebpackProcess extends ProcessWrapper { JSON.stringify(assets) ); } catch (e) { - console.error(e.message); - return callback(e); - // ?? should return e or e.message + return callback(errorMessage(e)); } const dappConfigPath = fs.dappPath('webpack.config.js'); @@ -60,15 +66,10 @@ class WebpackProcess extends ProcessWrapper { } else if (Array.isArray(config)) { config = config.filter(cfg => cfg.name === this.webpackConfigName); if (!config.length) { - const errMsg = `no webpack config has the name '${this.webpackConfigName}'`; - console.error(errMsg); - return callback(errMsg); - // ?? should the message be wrapped in new Error() + return callback(`no webpack config has the name '${this.webpackConfigName}'`); } if (config.length > 1) { - console.warn( - `detected ${config.length} webpack configs having the name '${this.webpackConfigName}', using the first one` - ); + console.warn(`detected ${config.length} webpack configs having the name '${this.webpackConfigName}', using the first one`); } config = config[0]; } else { @@ -76,22 +77,16 @@ class WebpackProcess extends ProcessWrapper { } } catch (e) { console.error(`error while loading webpack config ${configPath}`); - console.error(e.message); - callback(e); - // ?? should return e or e.message + callback(errorMessage(e)); } if (typeof config !== 'object' || config === null) { - const errMsg = 'bad webpack config, the resolved config was null or not an object'; - console.error(errMsg); - return callback(errMsg); - // ?? should the message be wrapped in new Error() + return callback('bad webpack config, the resolved config was null or not an object'); } webpack(config).run(async (err, stats) => { if (err) { - console.error(err); - return callback(err); + return callback(errorMessage(err)); } try { if (config.stats && config.stats !== 'none') { @@ -107,12 +102,10 @@ class WebpackProcess extends ProcessWrapper { ); } } catch (e) { - console.error(e.message); - return callback(err); + return callback(errorMessage(e)); } if (config.stats && stats.hasErrors()) { const errors = stats.toJson(config.stats).errors.join('\n'); - console.error(errors); return callback(errors); } callback();