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

Commit 08be292

Browse files
committed
fix: rethrow errors
1 parent 716f4f1 commit 08be292

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ export default function (o: Rx.Subject<Message>): Rx.Observable<any> {
5555
return bangify(wrap(msg), bang)
5656
}
5757

58-
const handleError = (scope: string) => async (err: NodeJS.ErrnoException) => {
58+
const handleError = (scope: string) => async (err: any) => {
5959
// ignore EPIPE errors
6060
// these come from using | head and | tail
6161
// and can be ignored
6262
try {
6363
if (err.code === 'EPIPE') return
64-
if (err.code === 'EEXIT' && typeof (err as any).status === 'number') {
65-
process.exit((err as any).status)
64+
if (typeof err.exitCode === 'number') {
65+
process.exit(err.exitCode)
6666
} else {
6767
const cli = new CLI(scope)
6868
cli.fatal(err, {exit: false})

src/exit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export class ExitError extends Error {
2-
public status: number
2+
public exitCode: number
33
public code: 'EEXIT'
44
public error?: Error
55

66
constructor(status: number, error?: Error) {
77
const code = 'EEXIT'
88
super(error ? error.message : `${code}: ${status}`)
99
this.error = error
10-
this.status = status
10+
this.exitCode = status
1111
this.code = code
1212
}
1313
}

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export class CLI {
3535
const error = input instanceof Error ? input : new Error(input)
3636
subject.next({type: 'error', scope: this.scope, severity: options.severity || 'error', error} as ErrorMessage)
3737
const code = getExitCode(options)
38-
if (code !== false) this.exit(code, error)
38+
if (code === false) return
39+
let exitErr: ExitError = error as any
40+
exitErr.exitCode = exitErr.exitCode || code
41+
throw exitErr
3942
}
4043

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

0 commit comments

Comments
 (0)