diff --git a/src/BaseCommand.js b/src/BaseCommand.js index 7acbde98..9a8e18cb 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -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 () { diff --git a/test/BaseCommand.test.js b/test/BaseCommand.test.js index fda6ac73..be3493d0 100644 --- a/test/BaseCommand.test.js +++ b/test/BaseCommand.test.js @@ -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' } }