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

Commit

Permalink
feat: allow printing errors without exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed May 12, 2018
1 parent 947fa59 commit 6694bc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/errors/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CLIError extends Error {
oclif: any
code?: string

constructor(error: string | Error, options: {code?: string, exit?: number} = {}) {
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
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ export function exit(code = 0): never {
throw new ExitError(code)
}

export function error(err: string | Error, options: {code?: string, exit?: number} = {}): never {
throw new CLIError(err, options)
export function error(input: string | Error, options: {code?: string, exit?: false}): void
export function error(input: string | Error, options?: {code?: string, exit?: number}): never
export function error(input: string | Error, options: {code?: string, exit?: number | false} = {}) {
const err = new CLIError(input, options)
if (options.exit === false) {
console.error(err.render ? err.render() : `Error ${err.message}`)
if (config.errorLogger) config.errorLogger.log(err.stack)
} else throw err
}

export function warn(input: string | Error) {
Expand Down

0 comments on commit 6694bc7

Please sign in to comment.