Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2719

Remove unnecessary errors returned by "bson.Encoder" and "bson.Decoder" APIs

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Major Change
    • Not Needed
    • Hide

      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?

      Show
      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?

      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.

            Assignee:
            qingyang.hu@mongodb.com Qingyang Hu
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: