Skip to content

Commit

Permalink
fix: handle errors without stack traces when using --verbose (#796)
Browse files Browse the repository at this point in the history
* handle errors without stack traces when using --verbose

* remove test log
  • Loading branch information
MichaelGoberling committed Apr 25, 2024
1 parent d1741cf commit e9d4bf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BaseCommand extends Command {
async catch (error) {
const { flags } = await this.parse(this.prototype)
aioLogger.error(error) // debug log
this.error(flags.verbose ? error.stack : error.message)
this.error(flags.verbose && error.stack ? error.stack : error.message)
}

async init () {
Expand Down
20 changes: 20 additions & 0 deletions test/BaseCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,26 @@ test('will change error message when aio app outside of the application root (--
expect(cmd.error).toHaveBeenCalledWith(expect.stringContaining(errorList.join('\n')))
})

test('will handle errors without stack traces when using --verbose flag', async () => {
const cmd = new TheCommand(['--verbose'])
cmd.error = jest.fn()
const errorWithoutStack = new Error('fake error')
delete errorWithoutStack.stack
await cmd.catch(errorWithoutStack)

expect(cmd.error).toHaveBeenCalledWith(expect.stringContaining('fake error'))
})

test('will handle errors without stack traces when not using --verbose flag', async () => {
const cmd = new TheCommand([])
cmd.error = jest.fn()
const errorWithoutStack = new Error('fake error')
delete errorWithoutStack.stack
await cmd.catch(errorWithoutStack)

expect(cmd.error).toHaveBeenCalledWith(expect.stringContaining('fake error'))
})

test('pjson', async () => {
const cmd = new TheCommand([])
cmd.config = { pjson: { name: 'fake', version: '0' } }
Expand Down

0 comments on commit e9d4bf8

Please sign in to comment.