Unwrap strict errors (#1012)

This commit is contained in:
Étienne BERSAC
2025-12-21 16:20:24 +01:00
committed by GitHub
parent a0e8464967
commit 4369957cb4
2 changed files with 27 additions and 1 deletions
+15
View File
@@ -205,6 +205,21 @@ func TestDecodeError_Accessors(t *testing.T) {
assert.Equal(t, "bar", e.String())
}
func TestStrictErrorUnwrap(t *testing.T) {
fo := bytes.NewBufferString(`
Missing = 1
OtherMissing = 1
`)
var out struct{}
err := NewDecoder(fo).DisallowUnknownFields().Decode(&out)
assert.Error(t, err)
strictErr := &StrictMissingError{}
assert.True(t, errors.As(err, &strictErr))
assert.Equal(t, 2, len(strictErr.Unwrap()))
}
func ExampleDecodeError() {
doc := `name = 123__456`