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

Improve the error message for bad YAML #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

smlx
Copy link
Member

@smlx smlx commented Nov 1, 2021

Attempt to generate some more easily human-parseable error messages for invalid .lagoon.yml.

This change tries to address #8 by making it easier to figure out exactly what the problem is.

For the .lagoon.yml in #8 it produces an error like this:

    lint_test.go:71: couldn't unmarshal testdata/invalid.4.lagoon.yml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array into Go struct field Lagoon.environments of type lagoonyml.Environment.
        There appears to be invalid YAML in the `environments` field:
        
        command: echo "broken definition"
        name: a cronjob defined as environment
        schedule: '* * * * *'
        service: cli

Because it uses the built-in JSON decoding errors this should automatically produce comprehensible errors when extending the .lagoon.yml validation.

@smlx smlx added the enhancement New feature or request label Nov 1, 2021
@smlx
Copy link
Member Author

smlx commented Nov 1, 2021

Annoyingly depending where the parsing chokes we can hit golang/go#44811 and generate garbage output due to the Offset being incorrect.

Not sure if that matters?

@smlx smlx force-pushed the improve-invalid-yaml-error branch from d7e92fa to 956e4dd Compare November 1, 2021 15:28
@smlx smlx changed the title feat: improve the error message for bad YAML Improve the error message for bad YAML Nov 1, 2021
@smlx smlx force-pushed the improve-invalid-yaml-error branch from 956e4dd to 8006af8 Compare November 1, 2021 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant