From b0346a08cac1fb1e3997df1c227de4a53fc351aa Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Tue, 15 Mar 2022 17:00:34 +0800 Subject: [PATCH] fix: show actual error when command is not run in an app folder --- src/BaseCommand.js | 8 ++++++-- test/BaseCommand.test.js | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/BaseCommand.js b/src/BaseCommand.js index f514d7ef..e15bfb7c 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -36,8 +36,12 @@ class BaseCommand extends Command { handleError (error) { 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', + 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 () => {