Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail earlier with malformed .lagoon.yml #297

Open
rocketeerbkw opened this issue Feb 7, 2024 · 2 comments
Open

Fail earlier with malformed .lagoon.yml #297

rocketeerbkw opened this issue Feb 7, 2024 · 2 comments

Comments

@rocketeerbkw
Copy link
Member

There is currently a validation step for .lagoon.yml but it doesn't happen before the build tool needs to parse information from the file. In the case where a user has committed a malformed file (like using tabs instead of spaces) the build will fail with a cryptic error message:

++ cat .lagoon.yml
++ shyaml get-value environment_variables.git_sha false
Traceback (most recent call last):
  File "/usr/bin/shyaml", line 8, in <module>
    sys.exit(entrypoint())
             ^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/shyaml.py", line 831, in entrypoint
    sys.exit(main(sys.argv[1:]))
             ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/shyaml.py", line 781, in main
    for output in do(stream=sys.stdin, **opts):
  File "/usr/lib/python3.11/site-packages/shyaml.py", line 661, in do
    for content in yaml.load_all(stream, Loader=loader):
  File "/usr/lib/python3.11/site-packages/yaml/__init__.py", line 93, in load_all
    yield loader.get_data()
          ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/yaml/constructor.py", line 45, in get_data
    return self.construct_document(self.get_node())
                                   ^^^^^^^^^^^^^^^
  File "yaml/_yaml.pyx", line 665, in yaml._yaml.CParser.get_node
  File "yaml/_yaml.pyx", line 687, in yaml._yaml.CParser._compose_document
  File "yaml/_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml/_yaml.pyx", line 845, in yaml._yaml.CParser._compose_mapping_node
  File "yaml/_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml/_yaml.pyx", line 845, in yaml._yaml.CParser._compose_mapping_node
  File "yaml/_yaml.pyx", line 731, in yaml._yaml.CParser._compose_node
  File "yaml/_yaml.pyx", line 847, in yaml._yaml.CParser._compose_mapping_node
  File "yaml/_yaml.pyx", line 860, in yaml._yaml.CParser._parse_next_event
yaml.parser.ParserError: while parsing a block mapping
  in "<stdin>", line 110, column 5
did not find expected key
  in "<stdin>", line 371, column 6

I think we should be able to do the validation step as the very first thing, before there are any calls to parse the file. This would be right after the git checkout and before the first shyaml call

if [ ! -f .lagoon.yml ]; then
echo "no .lagoon.yml file found"; exit 1;
fi

Can our validator give a more useful error message about where in the yaml file the error is? Even if it can't, at least having the error put into the section that says There are issues with your .lagoon.yml file that must be fixed. would be an improvement.

Additionally, we might also move the storing of the .lagoon.yml pre-deploy configmap before the validaton step? Then lagoon administrators would be able to look at the file in the case of an error.

@shreddedbacon
Copy link
Member

The entire structure of these files needs to be tweaked, and this is part of the work for moving more and more into go

@shreddedbacon
Copy link
Member

PR #289 does some work to remove some of the shyaml. That PR still leaves the shyaml check for the git_sha there, but I think it can actually be removed if you read the comment I've left in the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants