Decoder: show struct field in type mismatch errors (#684)
The goal is to provide some context as to why the type were mismatched. This change only works for that case, on structs. This is the same a encoding/json. A more general solution would be great, but this would require a broader change in the decoder, which I don't think is necessary at the moment. Fixes #628
This commit is contained in:
@@ -1790,6 +1790,20 @@ func TestUnmarshalOverflows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalErrors(t *testing.T) {
|
||||
type mystruct struct {
|
||||
Bar string
|
||||
}
|
||||
|
||||
data := `bar = 42`
|
||||
|
||||
s := mystruct{}
|
||||
err := toml.Unmarshal([]byte(data), &s)
|
||||
require.Error(t, err)
|
||||
|
||||
require.Equal(t, "toml: cannot decode TOML integer into struct field toml_test.mystruct.Bar of type string", err.Error())
|
||||
}
|
||||
|
||||
func TestUnmarshalInvalidTarget(t *testing.T) {
|
||||
x := "foo"
|
||||
err := toml.Unmarshal([]byte{}, x)
|
||||
|
||||
Reference in New Issue
Block a user