diff --git a/src/BaseCommand.js b/src/BaseCommand.js index f514d7ef..e34f66c3 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -29,15 +29,21 @@ const { class BaseCommand extends Command { // default error handler for app commands async catch (error) { + const { flags } = this.parse(this.prototype) aioLogger.error(error) // debug log - this.handleError(error) + this.handleError(error, flags.verbose) } - handleError (error) { + handleError (error, verbose) { const errorMessages = ['no such file or directory', 'find configuration'] + if (errorMessages.find(msg => error.message.includes(msg))) { - this.error(`Not a valid application root folder. -Please run 'aio app' commands from a folder generated by aio app init`) + const errorList = [ + 'Not a valid application root folder.', + 'Please run \'aio app\' commands from a folder generated by aio app init', + verbose ? error.stack : error.message + ] + this.error(errorList.join('\n')) } this.error(error.message) } diff --git a/test/BaseCommand.test.js b/test/BaseCommand.test.js index 6b35fcb1..5ccf36e2 100644 --- a/test/BaseCommand.test.js +++ b/test/BaseCommand.test.js @@ -241,8 +241,13 @@ test('will change error message when aio app outside of the application root', a const cmd = new TheCommand([]) cmd.error = jest.fn() await cmd.catch(new Error('ENOENT: no such file or directory, open \'package.json\'')) - expect(cmd.error).toHaveBeenCalledWith(`Not a valid application root folder. -Please run 'aio app' commands from a folder generated by aio app init`) + + const errorList = [ + 'Not a valid application root folder.', + 'Please run \'aio app\' commands from a folder generated by aio app init', + 'ENOENT: no such file or directory, open \'package.json\'' + ] + expect(cmd.error).toHaveBeenCalledWith(errorList.join('\n')) }) test('pjson', async () => {