Errors
The pretty rendering
Every error carries the token it was raised at, so it can be printed with the
source around it. errors.FormatError does that:
The two booleans are colored and inclSource. FormatErrorAtToken does the
same for a message and a token of your own, which is what you want when your
program rejects a document the parser accepted.
Telling one failure from another
Match on the sentinels with errors.Is:
Or take the error apart with errors.As and an *errors.Error, which carries
the token and therefore the position.
The conditions the library distinguishes: syntax, type mismatch, overflow, duplicate key, unknown field, unknown anchor, recursive alias, excessive aliasing, unhashable key, not-JSON, and unexpected node type.
Pointing at a value your own code rejected
The parse succeeded, your validation did not, and you want the same rendering. Address the value by path and annotate the source:
See YAMLPath for the path syntax.