Skip to content

Commit b0290dd

Browse files
authored
Fixed nil lastErr "%!w()" (#1956)
1 parent f4d278a commit b0290dd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

internal/pool/pool.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pool
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"sync"
78
"time"
@@ -876,12 +877,17 @@ func (p *Pool[PT, T]) getItem(ctx context.Context) (item PT, finalErr error) { /
876877
p.mu.RLock()
877878
defer p.mu.RUnlock()
878879

879-
return nil, xerrors.WithStackTrace(
880-
fmt.Errorf("failed to get item from pool after %d attempts and %v, pool has %d items (%d busy, "+
881-
"%d idle, %d create_in_progress): %w", attempt, p.config.clock.Since(start), len(p.index),
882-
len(p.index)-p.idle.Len(), p.idle.Len(), p.createInProgress, lastErr,
883-
),
880+
errMsg := fmt.Sprintf(
881+
"failed to get item from pool after %d attempts and %v, pool has %d items (%d busy, %d idle, %d create_in_progress)", //nolint:lll
882+
attempt, p.config.clock.Since(start), len(p.index),
883+
len(p.index)-p.idle.Len(), p.idle.Len(), p.createInProgress,
884884
)
885+
886+
if lastErr != nil {
887+
return nil, xerrors.WithStackTrace(fmt.Errorf(errMsg+": %w", lastErr))
888+
}
889+
890+
return nil, xerrors.WithStackTrace(errors.New(errMsg))
885891
}
886892

887893
//nolint:funlen

0 commit comments

Comments
 (0)