Skip to content

Commit

Permalink
GODRIVER-2243 Wrap write errors in IndexView.CreateMany (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
reillywatson authored and benjirewis committed Dec 8, 2021
1 parent 3c1c1d7 commit d3f6dae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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.
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

0 comments on commit d3f6dae

Please sign in to comment.