diff --git a/decoder.go b/decoder.go index 8774531..435591e 100644 --- a/decoder.go +++ b/decoder.go @@ -2,6 +2,7 @@ package maxminddb import ( "encoding/binary" + "fmt" "math" "math/big" "reflect" @@ -615,7 +616,7 @@ func (d *decoder) decodeMap( offset, err = d.decode(offset, elemValue, depth) if err != nil { - return 0, err + return 0, fmt.Errorf("decoding value for %s: %w", key, err) } keyValue.SetString(string(key)) @@ -772,7 +773,7 @@ func (d *decoder) decodeStruct( offset, err = d.decode(offset, result.Field(j), depth) if err != nil { - return 0, err + return 0, fmt.Errorf("decoding value for %s: %w", key, err) } } return offset, nil diff --git a/reader_test.go b/reader_test.go index f40541e..53ff1cd 100644 --- a/reader_test.go +++ b/reader_test.go @@ -594,7 +594,7 @@ func TestBrokenDoubleDatabase(t *testing.T) { expected := newInvalidDatabaseError( "the MaxMind DB file's data section contains bad data (float 64 size of 2)", ) - assert.Equal(t, expected, err) + assert.ErrorAs(t, err, &expected) assert.NoError(t, reader.Close(), "error on close") }