pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.67k stars 208 forks source link

Add more context to type errors #952

Open ayuhito opened 1 month ago

ayuhito commented 1 month ago

Describe the issue The current error types returned are almost enough context to create a pretty-error wrapper, but not quite everything needed.

For example, StrictMissingError returns enough context to generate an error message like this:

image

However, the generic DecodeError struct, which appears for type errors, lacks additional functions to identify which key doesn't match what type, making it difficult to build a pretty-error wrapper around it.

image

Currently, the solution I have implemented produces the above output, but it is not very user-friendly. Adding more context to the DecodeError struct, such as type information and the specific key responsible, would be really helpful. Additionally, I think there is a bug where DecodeError.Key() returns an empty list for this, making it impossible to programmatically name the responsible key.

Thank you for the awesome library!