From 8b60852be1de75a834c82188032674d67355c5aa Mon Sep 17 00:00:00 2001 From: Mohammad Fares Date: Mon, 1 Oct 2018 12:25:24 +0300 Subject: [PATCH] Enhance error handling --- app.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 2c0389c..e2adaa2 100644 --- a/app.js +++ b/app.js @@ -86,14 +86,28 @@ yargs.command(require('./commands/init.js')) .command(require('./commands/share.js')) .command(require('./commands/generate.js')) -/** - * Print exceptions - * - * @param {String} message - */ -function errorHandler(message) { +try { - console.error('Error: \n ' + message + '\n'); + // Parse the command line arguments + yargs.parse(); + +} catch (error) { + + // Print the error + errorHandler(error); + +} + +/** + * Print an error + * + * @param {String|Error} error + */ +function errorHandler(error) { + + error = error.toString(); + + console.error('Error: \n ' + error + '\n'); console.error('Hint:\n Use the ' + chalk.green('--help') + ' option to get help about the usage'); process.exit(1);