fauna / fauna-shell

Interactive shell for FaunaDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong error handling and wrong `exitCode`

zvictor opened this issue · 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.