fauna/fauna-shell

Wrong error handling and wrong `exitCode`

zvictor opened this issue · 1 comments

Description

The way errors are handled by this tool make it near impossible to build other tools or scripts on top of it in a reliable manner.
As soon as an error is thrown, the script calling fauna is broken.

Here is an example of intended behaviour, but that fails as soon as an error is thrown.

Steps to reproduce the error:

1- Copy the code below into /tmp/role.fql:

CreateRole({ name: "user",
  membership: [{ resource: Collection('User') }],
  privileges: [
    {
      resource: Function('logout'),
      actions: { call: true }
    }
  ]
})

2- Run the code below (or any code that would trigger a remote error within fauna):

npx fauna eval --format=json --file=/tmp/role.fql && echo '\nSuccess! No error code!'

Output:

{
  errors: [
    ...
    ...
  ]
}

Success! No error code!

Desired behaviour

  1. The exitCode should clearly never be 0 when the output is an error (which would then not let Success! No error code! be shown).
  2. The error message should go in the stderr but instead goes in stdout.
  3. The message has a JSON-like structure, but can't be parsed by any script because is not valid JSON.

Looks like this was largely resolved in #158 - going to close. Reopen if there's outstanding work.