Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show actual error when command is not run in an app folder #521

Merged
merged 3 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions test/BaseCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down