Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 6694bc7

Browse files
committed
feat: allow printing errors without exiting
1 parent 947fa59 commit 6694bc7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/errors/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class CLIError extends Error {
1111
oclif: any
1212
code?: string
1313

14-
constructor(error: string | Error, options: {code?: string, exit?: number} = {}) {
14+
constructor(error: string | Error, options: {code?: string, exit?: number | false} = {}) {
1515
const addExitCode = (error: any) => {
1616
error.oclif = error.oclif || {}
1717
error.oclif.exit = options.exit === undefined ? 2 : options.exit

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ export function exit(code = 0): never {
1414
throw new ExitError(code)
1515
}
1616

17-
export function error(err: string | Error, options: {code?: string, exit?: number} = {}): never {
18-
throw new CLIError(err, options)
17+
export function error(input: string | Error, options: {code?: string, exit?: false}): void
18+
export function error(input: string | Error, options?: {code?: string, exit?: number}): never
19+
export function error(input: string | Error, options: {code?: string, exit?: number | false} = {}) {
20+
const err = new CLIError(input, options)
21+
if (options.exit === false) {
22+
console.error(err.render ? err.render() : `Error ${err.message}`)
23+
if (config.errorLogger) config.errorLogger.log(err.stack)
24+
} else throw err
1925
}
2026

2127
export function warn(input: string | Error) {

0 commit comments

Comments
 (0)