-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: BSON
-
None
The bson.NewEncoder and bson.NewDecoder functions (and New*ValueWriter/New*DocumentReader functions) currently return an error that only informs the user that they've passed in a nil ValueWriter or ValueReader, respectively. That error makes the API awkward to use and could be replaced by a panic because there's typically no way to recover from a missing ValueWriter or ValueReader (i.e. that's an implementation error, not a runtime error). Remove the returned errors to make the API nicer to use.
Definition of done:
- Remove the error returned from:
- bson.NewEncoder
- bson.NewDecoder
- Decoder.Reset
- Decoder.SetRegistry
- Decoder.SetContext (Deprecated)
- Encoder.Reset
- Encoder.SetRegistry
- Encoder.SetContext (Deprecated)
- (Optional) Explicitly panic if the ValueWriter or ValueReader argument is nil.
Note that the alternative is to let subsequent calls to Encode/Decode panic with a "nil pointer dereference" (which is what the Go "encoding/json" library does). An explicit panic may be easier to understand, but the user will get a panic one way or another if they pass nil. - Remove the error returned from bson.NewBSONValueWriter and bson.NewExtJSONValueWriter.
- Rename bson.NewBSONValueWriter to bson.NewValueWriter.
- Rename NewBSONDocumentReader to NewValueReader.
- Remove NewBSONValueReader; do not support creating single-value-reader decoders (that's what UnmarshalValue is for).
- (Optional) Panic if the io.Writer or io.Reader argument is nil.
- related to
-
GODRIVER-2835 Support reading a stream of BSON documents with Decoder
- Closed