From 650a7e9facea508dd452cf3cd9cca67ced304e28 Mon Sep 17 00:00:00 2001 From: Victor Conner Date: Tue, 11 Mar 2025 08:35:27 +0100 Subject: [PATCH] Join ErrOnlyCachedRecords with the original error --- .golangci.yml | 8 -------- cache.go | 1 + fetch.go | 4 ++-- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c9313c7..303e8fd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,7 +42,6 @@ linters: - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error - errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 - exhaustive # checks exhaustiveness of enum switch statements - - exportloopref # checks for pointers to enclosing loop variables - forbidigo # forbids identifiers - funlen # tool for detection of long functions - gocheckcompilerdirectives # validates go compiler directive comments (//go:) @@ -79,7 +78,6 @@ linters: - sloglint # ensure consistent code style when using log/slog - sqlclosecheck # checks that sql.Rows and sql.Stmt are closed - stylecheck # is a replacement for golint - - tenv # detects using os.Setenv instead of t.Setenv since Go1.17 - testableexamples # checks if examples are testable (have an expected output) - testifylint # checks usage of github.com/stretchr/testify - testpackage # makes you use a separate _test package @@ -239,12 +237,6 @@ linters-settings: packages: - github.com/jmoiron/sqlx - tenv: - # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. - # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. - # Default: false - all: true - issues: # Maximum count of issues with the same text. # Set to 0 to disable. diff --git a/cache.go b/cache.go index 8d5aba1..7b7043e 100644 --- a/cache.go +++ b/cache.go @@ -121,6 +121,7 @@ func (c *Client[T]) performContinuousEvictions() { func (c *Client[T]) getShard(key string) *shard[T] { hash := xxhash.Sum64String(key) shardIndex := hash % uint64(len(c.shards)) + //nolint:gosec // we'll ignore potential integer overflows here. c.reportShardIndex(int(shardIndex)) return c.shards[shardIndex] } diff --git a/fetch.go b/fetch.go index 93b1740..0ffc292 100644 --- a/fetch.go +++ b/fetch.go @@ -63,7 +63,7 @@ func getFetch[V, T any](ctx context.Context, c *Client[T], key string, fetchFn F // then decide whether to proceed with the cached data or to // propagate the error. if err != nil && ok { - return value, ErrOnlyCachedRecords + return value, errors.Join(ErrOnlyCachedRecords, err) } return res, err @@ -176,7 +176,7 @@ func getFetchBatch[V, T any](ctx context.Context, c *Client[T], ids []string, ke if err != nil && !errors.Is(err, ErrOnlyCachedRecords) { if len(cachedRecords) > 0 { - return cachedRecords, ErrOnlyCachedRecords + return cachedRecords, errors.Join(ErrOnlyCachedRecords, err) } return cachedRecords, err }