@@ -223,10 +223,12 @@ func (c *Catalog) doCreateCollection(
223223 }
224224
225225 err := runWithRetry (ctx , func (ctx context.Context ) error {
226- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
226+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
227+
228+ return errors .Wrapf (err , "create collection %s.%s" , db , coll )
227229 })
228230 if err != nil {
229- return errors . Wrap ( err , "create collection" )
231+ return err //nolint:wrapcheck
230232 }
231233
232234 log .Ctx (ctx ).Debugf ("Created collection %s.%s" , db , coll )
@@ -256,10 +258,12 @@ func (c *Catalog) doCreateView(
256258 }
257259
258260 err := runWithRetry (ctx , func (ctx context.Context ) error {
259- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
261+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
262+
263+ return errors .Wrapf (err , "create view %s.%s" , db , view )
260264 })
261265 if err != nil {
262- return errors . Wrap ( err , "create view" )
266+ return err //nolint:wrapcheck
263267 }
264268
265269 log .Ctx (ctx ).Debugf ("Created view %s.%s" , db , view )
@@ -270,7 +274,9 @@ func (c *Catalog) doCreateView(
270274// DropCollection drops a collection in the target MongoDB.
271275func (c * Catalog ) DropCollection (ctx context.Context , db , coll string ) error {
272276 err := runWithRetry (ctx , func (ctx context.Context ) error {
273- return c .target .Database (db ).Collection (coll ).Drop (ctx )
277+ err := c .target .Database (db ).Collection (coll ).Drop (ctx )
278+
279+ return errors .Wrapf (err , "drop collection %s.%s" , db , coll )
274280 })
275281 if err != nil {
276282 return err //nolint:wrapcheck
@@ -299,10 +305,12 @@ func (c *Catalog) DropDatabase(ctx context.Context, db string) error {
299305 for _ , coll := range colls {
300306 eg .Go (func () error {
301307 err := runWithRetry (grpCtx , func (ctx context.Context ) error {
302- return c .target .Database (db ).Collection (coll ).Drop (ctx )
308+ err := c .target .Database (db ).Collection (coll ).Drop (ctx )
309+
310+ return errors .Wrapf (err , "drop namespace %s.%s" , db , coll )
303311 })
304312 if err != nil {
305- return errors . Wrapf ( err , "drop namespace %s.%s" , db , coll )
313+ return err // nolint:wrapcheck
306314 }
307315
308316 lg .Debugf ("Dropped collection %s.%s" , db , coll )
@@ -382,10 +390,12 @@ func (c *Catalog) CreateIndexes(
382390 // which does not support `prepareUnique`.
383391 for _ , index := range idxs {
384392 err := runWithRetry (ctx , func (ctx context.Context ) error {
385- return c .target .Database (db ).RunCommand (ctx , bson.D {
393+ err := c .target .Database (db ).RunCommand (ctx , bson.D {
386394 {"createIndexes" , coll },
387395 {"indexes" , bson.A {index }},
388396 }).Err ()
397+
398+ return errors .Wrapf (err , "create index %s.%s.%s" , db , coll , index .Name )
389399 })
390400 if err != nil {
391401 processedIdxs [index .Name ] = err
@@ -512,7 +522,9 @@ func (c *Catalog) ModifyCappedCollection(
512522 }
513523
514524 return runWithRetry (ctx , func (ctx context.Context ) error {
515- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
525+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
526+
527+ return errors .Wrapf (err , "modify capped collection %s.%s" , db , coll )
516528 }) //nolint:wrapcheck
517529}
518530
@@ -525,7 +537,9 @@ func (c *Catalog) ModifyView(ctx context.Context, db, view, viewOn string, pipel
525537 }
526538
527539 return runWithRetry (ctx , func (ctx context.Context ) error {
528- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
540+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
541+
542+ return errors .Wrapf (err , "modify view %s.%s" , db , view )
529543 }) //nolint:wrapcheck
530544}
531545
@@ -541,7 +555,9 @@ func (c *Catalog) ModifyChangeStreamPreAndPostImages(
541555 }
542556
543557 return runWithRetry (ctx , func (ctx context.Context ) error {
544- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
558+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
559+
560+ return errors .Wrapf (err , "modify changeStreamPreAndPostImages %s.%s" , db , coll )
545561 }) //nolint:wrapcheck
546562}
547563
@@ -568,7 +584,9 @@ func (c *Catalog) ModifyValidation(
568584 }
569585
570586 return runWithRetry (ctx , func (ctx context.Context ) error {
571- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
587+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
588+
589+ return errors .Wrapf (err , "modify validation %s.%s" , db , coll )
572590 }) //nolint:wrapcheck
573591}
574592
@@ -584,10 +602,12 @@ func (c *Catalog) ModifyIndex(ctx context.Context, db, coll string, mods *Modify
584602 }
585603
586604 err := runWithRetry (ctx , func (ctx context.Context ) error {
587- return c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
605+ err := c .target .Database (db ).RunCommand (ctx , cmd ).Err ()
606+
607+ return errors .Wrapf (err , "modify index %s.%s.%s" , db , coll , mods .Name )
588608 })
589609 if err != nil {
590- return errors . Wrap ( err , "modify index: " + mods . Name )
610+ return err //nolint:wrapcheck
591611 }
592612 }
593613
@@ -629,7 +649,9 @@ func (c *Catalog) Rename(ctx context.Context, db, coll, targetDB, targetColl str
629649 }
630650
631651 err := runWithRetry (ctx , func (ctx context.Context ) error {
632- return c .target .Database ("admin" ).RunCommand (ctx , opts ).Err ()
652+ err := c .target .Database ("admin" ).RunCommand (ctx , opts ).Err ()
653+
654+ return errors .Wrapf (err , "rename collection %s.%s to %s.%s" , db , coll , targetDB , targetColl )
633655 })
634656 if err != nil {
635657 if topo .IsNamespaceNotFound (err ) {
@@ -638,7 +660,7 @@ func (c *Catalog) Rename(ctx context.Context, db, coll, targetDB, targetColl str
638660 return nil
639661 }
640662
641- return errors . Wrap ( err , "rename collection" )
663+ return err //nolint:wrapcheck
642664 }
643665
644666 lg .Debugf ("Renamed collection %s.%s to %s.%s" , db , coll , targetDB , targetColl )
@@ -653,7 +675,9 @@ func (c *Catalog) DropIndex(ctx context.Context, db, coll, index string) error {
653675 lg := log .Ctx (ctx )
654676
655677 err := runWithRetry (ctx , func (ctx context.Context ) error {
656- return c .target .Database (db ).Collection (coll ).Indexes ().DropOne (ctx , index )
678+ err := c .target .Database (db ).Collection (coll ).Indexes ().DropOne (ctx , index )
679+
680+ return errors .Wrapf (err , "drop index %s.%s.%s" , db , coll , index )
657681 })
658682 if err != nil {
659683 if ! topo .IsNamespaceNotFound (err ) && ! topo .IsIndexNotFound (err ) {
@@ -859,10 +883,12 @@ func (c *Catalog) finalizeUnsuccessfulIndexes(ctx context.Context) {
859883 }
860884
861885 err := runWithRetry (ctx , func (ctx context.Context ) error {
862- return c .target .Database (db ).RunCommand (ctx , bson.D {
886+ err := c .target .Database (db ).RunCommand (ctx , bson.D {
863887 {"createIndexes" , coll },
864888 {"indexes" , bson.A {index .IndexSpecification }},
865889 }).Err ()
890+
891+ return errors .Wrapf (err , "recreate index %s.%s.%s" , db , coll , index .Name )
866892 })
867893 if err != nil {
868894 lg .Warnf ("Failed to recreate unsuccessful index %s on %s.%s: %v" ,
@@ -889,13 +915,15 @@ func (c *Catalog) doModifyIndexOption(
889915 value any ,
890916) error {
891917 return runWithRetry (ctx , func (ctx context.Context ) error {
892- return c .target .Database (db ).RunCommand (ctx , bson.D {
918+ err := c .target .Database (db ).RunCommand (ctx , bson.D {
893919 {"collMod" , coll },
894920 {"index" , bson.D {
895921 {"name" , index },
896922 {propName , value },
897923 }},
898924 }).Err ()
925+
926+ return errors .Wrapf (err , "modify index %s.%s.%s: %s" , db , coll , index , propName )
899927 }) //nolint:wrapcheck
900928}
901929
0 commit comments