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

config: Pretty print yaml parser errors #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func FromYAMLFile(name string, v Validator) error {

d := yaml.NewDecoder(f, yaml.DisallowUnknownField())
if err := d.Decode(v); err != nil {
// The PrettyPrint() method of the yaml parser errors doesn't get triggered automatically, so we've to do
// it via the `yaml.FormatError` helper function. If the provided error implements `yaml.errors.PrettyPrinter`
// we'll get the prettified string of that type, otherwise just error string.
err = errors.New(yaml.FormatError(err, true, true))
return errors.Wrap(err, "can't parse YAML file "+name)
}

Expand Down
Loading