Skip to content

Commit

Permalink
feat(utils): add utility for handling errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed May 29, 2019
1 parent 20da1f1 commit 70f701d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
31 changes: 31 additions & 0 deletions src/utils/handleError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* @adonisjs/ace
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* 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)
}

0 comments on commit 70f701d

Please sign in to comment.