@@ -90,23 +90,36 @@ func doTx(ctx context.Context, c SessionProvider, op table.TxOperation, opts ...
9090 options .options .Idempotent ,
9191 func (ctx context.Context , s table.Session ) (err error ) {
9292 tx , err := s .BeginTransaction (ctx , options .options .TxSettings )
93+ if err != nil {
94+ err = errors .Errorf (0 , "begin transaction failed: %w" , err )
95+ }
96+
9397 defer func () {
9498 if err != nil {
9599 _ = tx .Rollback (ctx )
96100 }
97101 }()
102+
98103 err = op (ctx , tx )
104+ if err != nil {
105+ err = errors .Errorf (0 , "retry operation failed: %w" , err )
106+ }
107+
99108 if attempts > 0 {
100109 onIntermediate (err )
101110 }
111+
102112 attempts ++
113+
103114 if err != nil {
104115 return err
105116 }
117+
106118 _ , err = tx .CommitTx (ctx , options .options .TxCommitOptions ... )
107119 if err != nil {
108120 err = errors .Errorf (0 , "commit failed: %w" , err )
109121 }
122+
110123 return err
111124 },
112125 options .trace ,
@@ -131,10 +144,16 @@ func do(ctx context.Context, c SessionProvider, op table.Operation, opts ...retr
131144 options .options .Idempotent ,
132145 func (ctx context.Context , s table.Session ) error {
133146 err = op (ctx , s )
147+ if err != nil {
148+ err = errors .Errorf (0 , "retry operation failed: %w" , err )
149+ }
150+
134151 if attempts > 0 {
135152 onIntermediate (err )
136153 }
154+
137155 attempts ++
156+
138157 return err
139158 },
140159 options .trace ,
@@ -250,8 +269,7 @@ func retryBackoff(
250269 }
251270 select {
252271 case <- ctx .Done ():
253- err = ctx .Err ()
254- return
272+ return errors .Errorf (0 , "context done: %w" , ctx .Err ())
255273
256274 default :
257275 if s == nil {
@@ -260,11 +278,14 @@ func retryBackoff(
260278 panic ("both of session and error are nil" )
261279 }
262280 if err != nil {
263- return
281+ return errors . Errorf ( 0 , "get session from pool failed: %w" , ctx . Err ())
264282 }
265283 }
266284
267285 err = op (ctx , s )
286+ if err != nil {
287+ err = errors .Errorf (0 , "retry operation failed: %w" , ctx .Err ())
288+ }
268289
269290 if s .isClosing () {
270291 _ = p .CloseSession (ctx , s )
0 commit comments