diff --git a/src/commands/eval.js b/src/commands/eval.js index 15537c03..5edff409 100644 --- a/src/commands/eval.js +++ b/src/commands/eval.js @@ -59,14 +59,12 @@ function performQuery(client, fqlQuery, outputFile, outputFormat) { return writeFormattedOutput(outputFile, response, outputFormat) }) .catch(function (error) { - console.error( + errorOut( util.inspect(JSON.parse(error.faunaError.requestResult.responseRaw), { depth: null, compact: false, }) ) - - process.exit(1) }) } diff --git a/test/commands/eval.test.js b/test/commands/eval.test.js index f6996121..ac171744 100644 --- a/test/commands/eval.test.js +++ b/test/commands/eval.test.js @@ -23,6 +23,20 @@ describe('eval', () => { .it('runs eval on nested db', (ctx) => { expect(JSON.parse(ctx.stdout).data[0].targetDb).to.equal('nested') }) + + test + .stderr() + .command(withOpts(['eval', '[Add(1, 2), Abort("boom")]'])) + .exit(1) + .it('Exits with non-zero code when the command fails') + + test + .stderr() + .command(withOpts(['eval', '[Add(1, 2), Abort("boom")]'])) + .catch((e) => { + expect(e.message).to.contain('transaction aborted') + }) + .it('It pretty-prints an error message the command fails') }) function mockQuery(api) {