Skip to content

Commit

Permalink
Remove MustConvertDocument (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed May 10, 2022
1 parent 61a166b commit ae325bd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
3 changes: 2 additions & 1 deletion internal/bson/bson.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/AlekSi/pointer"

"github.com/FerretDB/FerretDB/internal/types"
"github.com/FerretDB/FerretDB/internal/util/must"
)

type bsontype interface {
Expand All @@ -44,7 +45,7 @@ type bsontype interface {
func fromBSON(v bsontype) any {
switch v := v.(type) {
case *Document:
return types.MustConvertDocument(v)
return must.NotFail(types.ConvertDocument(v))
case *arrayType:
return pointer.To(types.Array(*v))
case *doubleType:
Expand Down
9 changes: 0 additions & 9 deletions internal/types/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"unicode/utf8"

"golang.org/x/exp/slices"

"github.com/FerretDB/FerretDB/internal/util/must"
)

// Common interface with bson.Document.
Expand Down Expand Up @@ -60,13 +58,6 @@ func ConvertDocument(d document) (*Document, error) {
return doc, nil
}

// MustConvertDocument is a ConvertDocument that panics in case of error.
//
// Deprecated: use `must.NotFail(ConvertDocument(...))` instead.
func MustConvertDocument(d document) *Document {
return must.NotFail(ConvertDocument(d))
}

// NewDocument creates a document with the given key/value pairs.
func NewDocument(pairs ...any) (*Document, error) {
l := len(pairs)
Expand Down
4 changes: 2 additions & 2 deletions internal/wire/op_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func (query *OpQuery) readFrom(bufr *bufio.Reader) error {
if err := q.ReadFrom(bufr); err != nil {
return err
}
query.Query = types.MustConvertDocument(&q)
query.Query = must.NotFail(types.ConvertDocument(&q))

if _, err := bufr.Peek(1); err == nil {
var r bson.Document
if err := r.ReadFrom(bufr); err != nil {
return err
}

tr := types.MustConvertDocument(&r)
tr := must.NotFail(types.ConvertDocument(&r))
query.ReturnFieldsSelector = tr
}

Expand Down
2 changes: 1 addition & 1 deletion internal/wire/op_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (reply *OpReply) readFrom(bufr *bufio.Reader) error {
if err := doc.ReadFrom(bufr); err != nil {
return lazyerrors.Errorf("wire.OpReply.ReadFrom: %w", err)
}
reply.Documents[i] = types.MustConvertDocument(&doc)
reply.Documents[i] = must.NotFail(types.ConvertDocument(&doc))
}

return nil
Expand Down

0 comments on commit ae325bd

Please sign in to comment.