Skip to content

Commit c813005

Browse files
authored
GODRIVER-2975 Fully support "errors.Is" and "errors.As" in BSON APIs. (#1984)
1 parent 9c23d50 commit c813005

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

bson/bson_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package bson
99
import (
1010
"bytes"
1111
"encoding/json"
12+
"errors"
1213
"fmt"
1314
"reflect"
1415
"strconv"
@@ -456,13 +457,14 @@ func TestD_UnmarshalJSON(t *testing.T) {
456457
want := json.Unmarshal([]byte(tc.test), &a)
457458
var b D
458459
got := json.Unmarshal([]byte(tc.test), &b)
459-
switch w := want.(type) {
460-
case *json.UnmarshalTypeError:
460+
w := new(json.UnmarshalTypeError)
461+
if errors.As(want, &w) {
461462
w.Type = reflect.TypeOf(b)
462463
require.IsType(t, want, got)
463-
g := got.(*json.UnmarshalTypeError)
464+
g := new(json.UnmarshalTypeError)
465+
assert.True(t, errors.As(got, &g))
464466
assert.Equal(t, w, g)
465-
default:
467+
} else {
466468
assert.Equal(t, want, got)
467469
}
468470
})

bson/registry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ func TestRegistry(t *testing.T) {
369369
t.Parallel()
370370

371371
wanterr := tc.wanterr
372-
if ene, ok := tc.wanterr.(errNoEncoder); ok {
372+
var ene errNoEncoder
373+
if errors.As(tc.wanterr, &ene) {
373374
wanterr = errNoDecoder(ene)
374375
}
375376

0 commit comments

Comments
 (0)