Add struct field location and context to errors reported when trying to unmarshal a string or integer into an inappropriate Go type.
Given this program:
type Server struct {
Path string
Port int
}
type Cfg struct {
Server Server
}
var cfg Cfg
data := `[server]
path = "/my/path"
port = "bad"`
file := strings.NewReader(data)
err := toml.NewDecoder(file).Decode(&cfg)
fmt.Println(err)
fmt.Println(err.(*toml.DecodeError).String()) // crashes on main
Output before patch:
toml: cannot store TOML string into a Go int
Output after patch:
toml: cannot decode TOML string into struct field toml_test.Server.Port of type int
1| [server]
2| path = "/my/path"
3| port = "bad"
| ~~~~~ cannot decode TOML string into struct field toml_test.Server.Port of type int
Add struct field location and context to errors reported when trying to unmarshal a string or integer into an inappropriate Go type.
Given this program:
Output before patch:
Output after patch:
Based on https://github.com/pelletier/go-toml/pull/890