diff --git a/packages/cli-command/src/command.js b/packages/cli-command/src/command.js index 435a6e520..b57c7f841 100644 --- a/packages/cli-command/src/command.js +++ b/packages/cli-command/src/command.js @@ -29,9 +29,11 @@ export default class PercyCommand extends Command { // real errors will bubble await super.catch(err); } catch (err) { - // oclif exit method actually throws an error, don't log it - if (!err.oclif || err.code !== 'EEXIT') log.error(err); - throw err; + // oclif exit method actually throws an error, let it continue + if (err.oclif && err.code === 'EEXIT') throw err; + // log all other errors and exit + log.error(err); + this.exit(1); } } diff --git a/packages/cli-command/test/command.test.js b/packages/cli-command/test/command.test.js index 876825a1f..b6610b7fc 100644 --- a/packages/cli-command/test/command.test.js +++ b/packages/cli-command/test/command.test.js @@ -68,14 +68,14 @@ describe('PercyCommand', () => { expect(log.loglevel()).toBe('silent'); }); - it('logs errors to the logger', async () => { + it('logs errors to the logger and exits', async () => { class TestPercyCommandError extends TestPercyCommand { test() { this.error('test error'); } } await expect(stdio.capture(() => ( TestPercyCommandError.run([]) - ))).rejects.toThrow('test error'); + ))).rejects.toThrow('EEXIT: 1'); expect(stdio[1]).toHaveLength(0); expect(stdio[2]).toEqual([