@@ -2,7 +2,6 @@ package retry
22
33import (
44 "context"
5-
65 "github.com/ydb-platform/ydb-go-sdk/v3/internal/backoff"
76 "github.com/ydb-platform/ydb-go-sdk/v3/internal/wait"
87 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
@@ -136,24 +135,21 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
136135 )
137136 defer func () {
138137 onIntermediate (err )(attempts , err )
139- if err != nil {
140- err = xerrors .Errorf ("error retried %d times: %w" , attempts - 1 , xerrors .WithStackTrace (err ))
141- }
142138 }()
143139 for {
144140 i ++
145141 attempts ++
146142 select {
147143 case <- ctx .Done ():
148- return xerrors .Errorf ("context done: " , ctx .Err ())
144+ return xerrors .WithStackTrace ( xerrors . Errorf ("retry failed (%d attempts): %w " , attempts , ctx .Err () ))
149145
150146 default :
151147 err = func () (err error ) {
152148 if options .panicCallback != nil {
153149 defer func () {
154150 if e := recover (); e != nil {
155151 options .panicCallback (e )
156- err = xerrors .Errorf ("panic recovered: %v" , e )
152+ err = xerrors .WithStackTrace ( xerrors . Errorf ("panic recovered: %v" , e ) )
157153 }
158154 }()
159155 }
@@ -165,7 +161,7 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
165161 }
166162
167163 if ctxErr := ctx .Err (); ctxErr != nil {
168- return xerrors .Errorf ("context error : %w" , ctxErr )
164+ return xerrors .WithStackTrace ( xerrors . Errorf ("retry failed (%d attempts) : %w" , ctx . Err ()) )
169165 }
170166
171167 m := Check (err )
@@ -175,11 +171,13 @@ func Retry(ctx context.Context, op retryOperation, opts ...retryOption) (err err
175171 }
176172
177173 if ! m .MustRetry (options .idempotent ) {
178- return xerrors .Errorf ("not retryable error : %w" , err )
174+ return xerrors .WithStackTrace ( xerrors . Errorf ("retry failed (%d attempts) : %w" , err ) )
179175 }
180176
181177 if e := wait .Wait (ctx , options .fastBackoff , options .slowBackoff , m .BackoffType (), i ); e != nil {
182- return xerrors .Errorf ("wait exit with error '%w' (origin error '%w')" , e , err )
178+ return xerrors .WithStackTrace (
179+ xerrors .Errorf ("retry failed (%d attempts): wait exit with error '%w' (origin error '%w')" , e , err ),
180+ )
183181 }
184182
185183 code = m .StatusCode ()
0 commit comments