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

Commit

Permalink
fix: Handle misformed error response (without stack) (#8)
Browse files Browse the repository at this point in the history
* fix: Handle misformed error response (without `stack`)

* test: Add test for POJO input

* test: Remove unused variable

* lint: Style fix
  • Loading branch information
jperasmus authored and jdx committed May 21, 2018
1 parent 0b2119f commit 9ae1790
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const handle = (err: any) => {
try {
if (!err) err = new Error('no error?')
if (err.message === 'SIGINT') process.exit(1)
let stack = clean(err.stack, {pretty: true})
let stack = clean(err.stack || '', {pretty: true})
let message = stack
if (err.oclif && typeof err.render === 'function') message = err.render()
if (message) console.error(message)
Expand Down
8 changes: 8 additions & 0 deletions test/handle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ describe('handle', () => {
expect(process.exitCode).to.equal(1)
})

fancy
.stderr()
.finally(() => delete process.exitCode)
.it('handles a badly formed error object', () => {
handle({status: 400})
expect(process.exitCode).to.equal(1)
})

fancy
.stderr()
.finally(() => delete process.exitCode)
Expand Down

0 comments on commit 9ae1790

Please sign in to comment.