pelletier / go-toml

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

UnmarshalText error readability #737

Closed thierry-f-78 closed 2 years ago

thierry-f-78 commented 2 years ago

Describe the bug

I use go-toml to parse a configuration file. The parsing errors are shown by a system administrator and not by a developper.

I implement a Marshaller to Unmarshal some type (time.Duration in example). When my duration is wring, I read this message:

2|  duration = "##fdsf"
 |             ~~~~~~~~ error calling UnmarshalText: invalid duration "##fdsf"
3|  

The administrator read an error strating by "error calling UnmarshalText", but this string is related to program internal behavior. The administrator dont care about this information. This information could be perturbated by this information and could contact software support.

To Reproduce

https://go.dev/play/p/6YvcBbolsFu

Expected behavior

I suggest when the marshaller return a error, the error is reported as-is (without prefix).

If you're ok, I could write a PR

Versions

pelletier commented 2 years ago

Sorry for the wait! I think that's a reasonable change. I am a little worried about the loss of information for a programmer who would be implementing unmarshaling for their own types, but at that point they probably know where the issue may be coming from. Feel free to open a PR!

pelletier commented 2 years ago

Removed in f5cc8c4. Let me know if that doesn't work for you!