55 "fmt"
66
77 "github.com/ydb-platform/ydb-go-sdk/v3/internal/backoff"
8+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
89 "github.com/ydb-platform/ydb-go-sdk/v3/internal/wait"
910 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1011 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
@@ -217,11 +218,12 @@ func isRetryCalledAbove(ctx context.Context) bool {
217218// Warning: if deadline without deadline or cancellation func Retry will be worked infinite
218219//
219220// If you need to retry your op func on some logic errors - you must return RetryableError() from retryOperation
220- func Retry (ctx context.Context , op retryOperation , opts ... Option ) (err error ) {
221+ func Retry (ctx context.Context , op retryOperation , opts ... Option ) (finalErr error ) {
221222 options := & retryOptions {
223+ trace : & trace.Retry {},
222224 fastBackoff : backoff .Fast ,
223225 slowBackoff : backoff .Slow ,
224- trace : & trace. Retry {} ,
226+ label : stack . Record ( 1 , stack . Lambda ( false ), stack . FileName ( false )) ,
225227 }
226228 for _ , opt := range opts {
227229 if opt != nil {
@@ -230,8 +232,8 @@ func Retry(ctx context.Context, op retryOperation, opts ...Option) (err error) {
230232 }
231233 ctx = xcontext .WithIdempotent (ctx , options .idempotent )
232234 defer func () {
233- if err != nil && options .stackTrace {
234- err = xerrors .WithStackTrace (err ,
235+ if finalErr != nil && options .stackTrace {
236+ finalErr = xerrors .WithStackTrace (finalErr ,
235237 xerrors .WithSkipDepth (2 ), // 1 - exit from defer, 1 - exit from Retry call
236238 )
237239 }
@@ -246,7 +248,7 @@ func Retry(ctx context.Context, op retryOperation, opts ...Option) (err error) {
246248 )
247249 )
248250 defer func () {
249- onIntermediate (err )(attempts , err )
251+ onIntermediate (finalErr )(attempts , finalErr )
250252 }()
251253 for {
252254 i ++
@@ -260,7 +262,7 @@ func Retry(ctx context.Context, op retryOperation, opts ...Option) (err error) {
260262 )
261263
262264 default :
263- err = func () (err error ) {
265+ err : = func () (err error ) {
264266 if options .panicCallback != nil {
265267 defer func () {
266268 if e := recover (); e != nil {
@@ -295,10 +297,8 @@ func Retry(ctx context.Context, op retryOperation, opts ...Option) (err error) {
295297
296298 if ! m .MustRetry (options .idempotent ) {
297299 return xerrors .WithStackTrace (
298- xerrors .Join (
299- fmt .Errorf ("non-retryable error occurred on attempt No.%d (idempotent=%v)" ,
300- attempts , options .idempotent ,
301- ), err ,
300+ fmt .Errorf ("non-retryable error occurred on attempt No.%d (idempotent=%v): %w" ,
301+ attempts , options .idempotent , err ,
302302 ),
303303 )
304304 }
0 commit comments