reanahub / reana-client

REANA command-line client
http://reana-client.readthedocs.io/
MIT License
10 stars 44 forks source link

validate: more explicit error messages in case of indentation troubles #676

Closed tiborsimko closed 8 months ago

tiborsimko commented 8 months ago

Current behaviour

The reana-client validate returns cryptic error message when there is a problem with reana.yaml validation:

$ cd reana-demo-root6-roofit
$ sed -i 's,^  parameters:,   parameters:,g' reana.yaml
$ reana-client validate
==> ERROR: Something went wrong when trying to validate reana.yaml

This is problematic because the users would not understand what's wong.

Expected behaviour

Users should be given hint that there is a problem with indentation of reana.yaml clauses.

For example, see what yamllint does:

$ yamllint --no-warnings reana.yaml
reana.yaml
  6:4       error    syntax error: expected <block end>, but found '<block mapping start>' (syntax)
  7:5       error    wrong indentation: expected 5 but found 4  (indentation)
  18:9      error    wrong indentation: expected 10 but found 8  (indentation)
  23:9      error    wrong indentation: expected 10 but found 8  (indentation)
mdonadoni commented 8 months ago

Two options:

(a) Expose the exception that is already thrown by yaml.load, like this:

==> ERROR: reana.yaml is not a valid YAML file:
while parsing a block mapping
  in "<unicode string>", line 3, column 3:
      files:
      ^
expected <block end>, but found '<block mapping start>'
  in "<unicode string>", line 6, column 4:
       parameters:
       ^

(b) Add yamllint to the dependencies of r-commons (as validation and parsing are there) and use it to check whether the YAML file is valid. It does not require too many dependencies:

$ pip install yamllint
$ pip freeze
pathspec==0.11.2
PyYAML==6.0.1
yamllint==1.32.0

Note that pyyaml and pathspec are already installed by reana-client (but not by cluster components)

I think option (a) might already be enough to find out where is the issue in the YAML file, even though it does not report specifically that there are indentation issues.

What do you think?