Enhance error handling

This commit is contained in:
Mohammad Fares 2018-10-01 12:25:24 +03:00
parent 17975aba21
commit 8b60852be1
1 changed files with 21 additions and 7 deletions

28
app.js
View File

@ -86,14 +86,28 @@ yargs.command(require('./commands/init.js'))
.command(require('./commands/share.js')) .command(require('./commands/share.js'))
.command(require('./commands/generate.js')) .command(require('./commands/generate.js'))
/** try {
* Print exceptions
*
* @param {String} message
*/
function errorHandler(message) {
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'); console.error('Hint:\n Use the ' + chalk.green('--help') + ' option to get help about the usage');
process.exit(1); process.exit(1);