diff --git a/index.ts b/index.ts index b06c0f5..32ed031 100644 --- a/index.ts +++ b/index.ts @@ -11,3 +11,4 @@ export { Kernel } from './src/Kernel' export { BaseCommand } from './src/BaseCommand' export { args } from './src/Decorators/args' export { flags } from './src/Decorators/flags' +export { handleError } from './src/utils/handleError' diff --git a/src/utils/handleError.ts b/src/utils/handleError.ts new file mode 100644 index 0000000..c69e95a --- /dev/null +++ b/src/utils/handleError.ts @@ -0,0 +1,31 @@ +/* +* @adonisjs/ace +* +* (c) Harminder Virk +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +import { red, bgRed } from 'kleur' + +/** + * Handles the command errors and prints them to the console. + */ +export function handleError (error: any) { + if (error.name === 'CommandValidationException') { + console.log(red(error.message)) + console.log(bgRed('This is a programming error. Make sure to read the docs')) + return + } + + if (error.name === 'InvalidArgumentException') { + console.log(bgRed('Error')) + console.log(red(error.message)) + return + } + + console.log(bgRed('Fatal error')) + console.log(red(error.message)) + console.log(error.stack) +}