[GODRIVER-2719] Remove unnecessary errors returned by "bson.Encoder" and "bson.Decoder" APIs Created: 23/Dec/22  Updated: 25/Jan/24  Resolved: 25/Jan/24

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Qingyang Hu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-2835 Support reading a stream of BSON docu... Backlog
Epic Link: Go Driver 2.0 BSON
Quarter: FY24Q3
Backwards Compatibility: Major Change
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

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.


 Comments   
Comment by Githook User [ 25/Jan/24 ]

Author:

{'name': 'Qingyang Hu', 'email': '103950869+qingyang-hu@users.noreply.github.com', 'username': 'qingyang-hu'}

Message: GODRIVER-2719 Remove unnecessary errors from `bson.Encoder`/`bson.Decoder`. (#1525)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/6109bd18ed746f828ad149e8c0018ae009a872cd

Generated at Thu Feb 08 08:39:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.