-
Notifications
You must be signed in to change notification settings - Fork 0
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
config: Pretty print yaml parser errors #86
base: main
Are you sure you want to change the base?
Conversation
The `PrettyPrint()` method of the yaml errors doesn't get triggered automatically, so we've to do it via the `yaml.FormatError()` helper function. This will return the prettified string of the provided error, if it implements the `yaml.errors#PrettyPrinter` interface, otherwise just the error string.
Why? I would rather not try to fix it here but in Icinga DB where we just do |
It is not a standard GO interface, none of the
This library is used by more than 1 project already and you want to do this in each one of them? Btw. Icinga DB uses not just |
I believe I've seen these pretty-printed YAML errors before1 and can't remember that we manually used Footnotes
|
Yes, |
The Syntax error: can't parse YAML file config.example.yml: [12:3] unknown field "hosts"
9 | # type: mysql
10 |
11 | # Database host or absolute Unix socket path.
> 12 | hosts: localhost
^
14 | # Database port. By default, the MySQL or PostgreSQL port, depending on the database type.
15 | # port:
16 |
exit status 1 type error: can't parse YAML file config.example.yml: cannot unmarshal string into Go struct field Config.Retention of type uint16
exit status 1
No, none of the errors implement such an interface. |
Why don't we fix it in the lib and submit a PR? I would actually introduce implementing |
The
PrettyPrint()
method of the yaml errors doesn't get triggered automatically, so we've to do it via theyaml.FormatError()
helper function. This will return the prettified string of the provided error, if it implements theyaml.errors#PrettyPrinter
interface, otherwise just the error string.Before
After
resolves Icinga/icingadb#755