Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/errors/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ import {config} from '../config'
export class CLIError extends Error {
oclif: any
code?: string
originalStack?: string

constructor(error: string | Error, options: {code?: string, exit?: number | false} = {}) {
const addExitCode = (error: any) => {
error.oclif = error.oclif || {}
error.oclif.exit = options.exit === undefined ? 2 : options.exit
return error
const defaultExit = 2
if (error instanceof Error) {
super(error.message)
this.oclif = (error as any).oclif || {}
this.oclif.exit = options.exit !== undefined ? options.exit :
this.oclif.exit !== undefined ? this.oclif.exit : defaultExit
this.originalStack = (error as any).originalStack || error.stack
this.code = options.code !== undefined ? options.code : (error as any).code
} else {
super(error)
this.oclif = {}
this.oclif.exit = options.exit !== undefined ? options.exit : defaultExit
this.code = options.code
}
if (error instanceof Error) return addExitCode(error as any)
super(error)
addExitCode(this)
this.code = options.code
}

get stack(): string {
const clean: typeof Clean = require('clean-stack')
return clean(super.stack!, {pretty: true})
return clean(this.originalStack ? this.originalStack : super.stack!, {pretty: true})
}

render(): string {
Expand Down