Skip to content

Commit

Permalink
Forward error to stderr and set exitCode (#158)
Browse files Browse the repository at this point in the history
* Forward error to stderr and set exitCode

* Add tests to confirm exit code

Co-authored-by: Cleve Stuart <[email protected]>
  • Loading branch information
zvictor and cleve-fauna authored Apr 4, 2022
1 parent 38c3ba5 commit b3c4c94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function performQuery(client, fqlQuery, outputFile, outputFormat) {
return writeFormattedOutput(outputFile, response, outputFormat)
})
.catch(function (error) {
console.log(
errorOut(
util.inspect(JSON.parse(error.faunaError.requestResult.responseRaw), {
depth: null,
compact: false,
Expand Down
14 changes: 14 additions & 0 deletions test/commands/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b3c4c94

Please sign in to comment.