Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2489 createPipelineOptionsDoc: return err #1036

Merged
merged 2 commits into from Aug 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions mongo/change_stream.go
Expand Up @@ -256,8 +256,8 @@ func (cs *ChangeStream) executeOperation(ctx context.Context, resuming bool) err
if resuming {
cs.replaceOptions(cs.wireVersion)

csOptDoc := cs.createPipelineOptionsDoc()
if cs.err != nil {
csOptDoc, err := cs.createPipelineOptionsDoc()
if err != nil {
return cs.Err()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to check an error and then return a different error. Update this to return err (instead of cs.Err()) if it's not nil.

}
pipIdx, pipDoc := bsoncore.AppendDocumentStart(nil)
Expand Down Expand Up @@ -386,8 +386,9 @@ func (cs *ChangeStream) buildPipelineSlice(pipeline interface{}) error {
cs.pipelineSlice = make([]bsoncore.Document, 0, val.Len()+1)

csIdx, csDoc := bsoncore.AppendDocumentStart(nil)
csDocTemp := cs.createPipelineOptionsDoc()
if cs.err != nil {

csDocTemp, err := cs.createPipelineOptionsDoc()
if err != nil {
return cs.err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: It's confusing to check an error and then return a different error. Update this to return err (instead of cs.err) if it's not nil.

}
csDoc = bsoncore.AppendDocumentElement(csDoc, "$changeStream", csDocTemp)
Expand All @@ -410,7 +411,7 @@ func (cs *ChangeStream) buildPipelineSlice(pipeline interface{}) error {
return cs.err
}

func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
func (cs *ChangeStream) createPipelineOptionsDoc() (bsoncore.Document, error) {
plDocIdx, plDoc := bsoncore.AppendDocumentStart(nil)

if cs.streamType == ClientStream {
Expand All @@ -434,7 +435,7 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
var raDoc bsoncore.Document
raDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.ResumeAfter, true, "resumeAfter")
if cs.err != nil {
return nil
return nil, cs.err
}

plDoc = bsoncore.AppendDocumentElement(plDoc, "resumeAfter", raDoc)
Expand All @@ -448,7 +449,7 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
var saDoc bsoncore.Document
saDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.StartAfter, true, "startAfter")
if cs.err != nil {
return nil
return nil, cs.err
}

plDoc = bsoncore.AppendDocumentElement(plDoc, "startAfter", saDoc)
Expand All @@ -464,10 +465,10 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
}

if plDoc, cs.err = bsoncore.AppendDocumentEnd(plDoc, plDocIdx); cs.err != nil {
return nil
return nil, cs.err
}

return plDoc
return plDoc, nil
}

func (cs *ChangeStream) pipelineToBSON() (bsoncore.Document, error) {
Expand Down