Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
fix: rethrow errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 19, 2018
1 parent 716f4f1 commit 08be292
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ export default function (o: Rx.Subject<Message>): Rx.Observable<any> {
return bangify(wrap(msg), bang)
}

const handleError = (scope: string) => async (err: NodeJS.ErrnoException) => {
const handleError = (scope: string) => async (err: any) => {
// ignore EPIPE errors
// these come from using | head and | tail
// and can be ignored
try {
if (err.code === 'EPIPE') return
if (err.code === 'EEXIT' && typeof (err as any).status === 'number') {
process.exit((err as any).status)
if (typeof err.exitCode === 'number') {
process.exit(err.exitCode)
} else {
const cli = new CLI(scope)
cli.fatal(err, {exit: false})
Expand Down
4 changes: 2 additions & 2 deletions src/exit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export class ExitError extends Error {
public status: number
public exitCode: number
public code: 'EEXIT'
public error?: Error

constructor(status: number, error?: Error) {
const code = 'EEXIT'
super(error ? error.message : `${code}: ${status}`)
this.error = error
this.status = status
this.exitCode = status
this.code = code
}
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export class CLI {
const error = input instanceof Error ? input : new Error(input)
subject.next({type: 'error', scope: this.scope, severity: options.severity || 'error', error} as ErrorMessage)
const code = getExitCode(options)
if (code !== false) this.exit(code, error)
if (code === false) return
let exitErr: ExitError = error as any
exitErr.exitCode = exitErr.exitCode || code
throw exitErr
}

fatal(input: Error | string, options: IErrorOptions = {}) { this.error(input, {...options, severity: 'fatal'}) }
Expand Down

0 comments on commit 08be292

Please sign in to comment.