Skip to content

Commit 1ae0377

Browse files
committed
GODRIVER-3425 Reference ObjectIdAsHexString decoder option in exception message
1 parent 563588a commit 1ae0377

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

bson/string_codec.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package bson
88

99
import (
10+
"errors"
1011
"fmt"
1112
"reflect"
1213
)
@@ -50,14 +51,16 @@ func (sc *stringCodec) decodeType(dc DecodeContext, vr ValueReader, t reflect.Ty
5051
return emptyValue, err
5152
}
5253
case TypeObjectID:
53-
oid, err := vr.ReadObjectID()
54-
if err != nil {
55-
return emptyValue, err
56-
}
5754
if dc.objectIDAsHexString {
55+
oid, err := vr.ReadObjectID()
56+
if err != nil {
57+
return emptyValue, err
58+
}
5859
str = oid.Hex()
5960
} else {
60-
return emptyValue, fmt.Errorf("decoding an object ID to a non-hexadecimal string representation is not supported")
61+
msg := "decoding an object ID into a plain string is not supported " +
62+
"(set Decoder.ObjectIDAsHexString to enable decoding as a hexadecimal representation)"
63+
return emptyValue, errors.New(msg)
6164
}
6265
case TypeSymbol:
6366
str, err = vr.ReadSymbol()

0 commit comments

Comments
 (0)