diff --git a/packages/whook-cli/src/services/command.ts b/packages/whook-cli/src/services/command.ts index 53c438a7..15caa3ce 100644 --- a/packages/whook-cli/src/services/command.ts +++ b/packages/whook-cli/src/services/command.ts @@ -15,20 +15,20 @@ async function initCommand({ commandHandler, log }) { 'error', `Argument "${err.params[0][0].params.missingProperty}" is required.`, ); - return; + throw err; } } if (err.params[0][0].keyword === 'additionalProperties') { if (err.params[0][0].params.additionalProperty === '_') { log('error', 'No anonymous arguments allowed.'); - return; + throw err; } if (err.params[0][0].params.additionalProperty) { log( 'error', `Argument "${err.params[0][0].params.additionalProperty}" not allowed.`, ); - return; + throw err; } } log( @@ -37,7 +37,7 @@ async function initCommand({ commandHandler, log }) { err.params[0][0].message, err.params[0][0].params, ); - return; + throw err; } throw err; } diff --git a/packages/whook-example/src/cli.test.ts b/packages/whook-example/src/cli.test.ts index 932acc91..f928f7b6 100644 --- a/packages/whook-example/src/cli.test.ts +++ b/packages/whook-example/src/cli.test.ts @@ -1,4 +1,5 @@ import { exec } from 'child_process'; +import YError from 'yerror'; describe('commands should work', () => { it('with ls', async () => { @@ -36,12 +37,12 @@ describe('commands should work', () => { }); async function execCommand( - command, + command: string, ): Promise<{ stdout: string; stderr: string }> { return new Promise((resolve, reject) => { exec(command, (err, stdout, stderr) => { if (err) { - reject(err); + reject(YError.wrap(err, 'E_COMMAND_FAILURE', stdout, stderr)); return; } resolve({ stdout, stderr });