@@ -2,7 +2,6 @@ package retry
22
33import (
44 "context"
5- "fmt"
65
76 "github.com/ydb-platform/ydb-go-sdk/v3/internal/backoff"
87 "github.com/ydb-platform/ydb-go-sdk/v3/internal/wait"
@@ -143,15 +142,15 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
143142 attempts ++
144143 select {
145144 case <- ctx .Done ():
146- return xerrors .WithStackTrace (ctx .Err ())
145+ return xerrors .WithStackTrace (xerrors . Errorf ( "retry failed on attempt No.%d: %w" , attempts , ctx .Err () ))
147146
148147 default :
149148 err = func () (err error ) {
150149 if options .panicCallback != nil {
151150 defer func () {
152151 if e := recover (); e != nil {
153152 options .panicCallback (e )
154- err = xerrors .WithStackTrace (fmt .Errorf ("panic recovered: %v" , e ))
153+ err = xerrors .WithStackTrace (xerrors .Errorf ("panic recovered: %v" , e ))
155154 }
156155 }()
157156 }
@@ -163,7 +162,7 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
163162 }
164163
165164 if ctxErr := ctx .Err (); ctxErr != nil {
166- return ctxErr
165+ return xerrors . WithStackTrace ( xerrors . Errorf ( "retry failed on attempt No.%d: %w" , attempts , ctx . Err ()))
167166 }
168167
169168 m := Check (err )
@@ -173,12 +172,12 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
173172 }
174173
175174 if ! m .MustRetry (options .idempotent ) {
176- return xerrors .WithStackTrace (err )
175+ return xerrors .WithStackTrace (xerrors . Errorf ( "retry failed on attempt No.%d: %w" , attempts , err ) )
177176 }
178177
179178 if e := wait .Wait (ctx , options .fastBackoff , options .slowBackoff , m .BackoffType (), i ); e != nil {
180179 return xerrors .WithStackTrace (
181- xerrors .Errorf ("wait exit with error '%w' (origin error '%w')" , e , err ),
180+ xerrors .Errorf ("retry failed on attempt No.%d: wait exit with error '%w' (origin error '%w')" , attempts , e , err ),
182181 )
183182 }
184183
0 commit comments