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-2243 Wrap write errors in IndexView.CreateMany #820

Merged
merged 1 commit into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion mongo/index_view.go
Expand Up @@ -272,7 +272,8 @@ func (iv IndexView) CreateMany(ctx context.Context, models []IndexModel, opts ..

err = op.Execute(ctx)
if err != nil {
return nil, replaceErrors(err)
_, err = processWriteError(err)
return nil, err
}

return names, nil
Expand Down
13 changes: 13 additions & 0 deletions mongo/integration/index_view_test.go
Expand Up @@ -263,6 +263,19 @@ func TestIndexView(t *testing.T) {
})
}
})
unackClientOpts := options.Client().
SetWriteConcern(writeconcern.New(writeconcern.W(0)))
unackMtOpts := mtest.NewOptions().
ClientOptions(unackClientOpts).
MinServerVersion("3.6")
mt.RunOpts("unacknowledged write", unackMtOpts, func(mt *mtest.T) {
_, err := mt.Coll.Indexes().CreateOne(mtest.Background, mongo.IndexModel{Keys: bson.D{{"x", 1}}})
if err != mongo.ErrUnacknowledgedWrite {
// Use a direct comparison rather than assert.Equal because assert.Equal will compare the error strings,
// so the assertion would succeed even if the error had not been wrapped.
Copy link
Contributor

Choose a reason for hiding this comment

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

Helpful comment, thank you!

mt.Fatalf("expected CreateOne error %v, got %v", mongo.ErrUnacknowledgedWrite, err)
}
})
// Needs to run on these versions for failpoints
mt.RunOpts("replace error", mtest.NewOptions().Topologies(mtest.ReplicaSet).MinServerVersion("4.0"), func(mt *mtest.T) {
mt.SetFailPoint(mtest.FailPoint{
Expand Down