diff --git a/src/errors.ts b/src/errors.ts index 2dcd57ae..b8afe0fb 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -55,14 +55,14 @@ export default function (o: Rx.Subject): Rx.Observable { 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}) diff --git a/src/exit.ts b/src/exit.ts index 18b33224..97827cdd 100644 --- a/src/exit.ts +++ b/src/exit.ts @@ -1,5 +1,5 @@ export class ExitError extends Error { - public status: number + public exitCode: number public code: 'EEXIT' public error?: Error @@ -7,7 +7,7 @@ export class ExitError extends Error { const code = 'EEXIT' super(error ? error.message : `${code}: ${status}`) this.error = error - this.status = status + this.exitCode = status this.code = code } } diff --git a/src/index.ts b/src/index.ts index 54c11c79..9c7d3556 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'}) }