From 924407959781e493443587c345d666de203e5d98 Mon Sep 17 00:00:00 2001 From: Bob Callaway Date: Fri, 4 Nov 2022 10:02:54 -0400 Subject: [PATCH] wrap redis client errors to aid debugging Signed-off-by: Bob Callaway --- pkg/api/index.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/api/index.go b/pkg/api/index.go index 2faa770ae..afda3aa90 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -19,6 +19,7 @@ import ( "context" "crypto/sha256" "encoding/hex" + "fmt" "net/http" "strings" @@ -47,7 +48,7 @@ func SearchIndexHandler(params index.SearchIndexParams) middleware.Responder { sha := util.PrefixSHA(params.Query.Hash) var resultUUIDs []string if err := redisClient.Do(httpReqCtx, radix.Cmd(&resultUUIDs, "LRANGE", strings.ToLower(sha), "0", "-1")); err != nil { - return handleRekorAPIError(params, http.StatusInternalServerError, err, redisUnexpectedResult) + return handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("redis client: %w", err), redisUnexpectedResult) } result.Add(resultUUIDs) } @@ -74,14 +75,14 @@ func SearchIndexHandler(params index.SearchIndexParams) middleware.Responder { keyHash := sha256.Sum256(canonicalKey) var resultUUIDs []string if err := redisClient.Do(httpReqCtx, radix.Cmd(&resultUUIDs, "LRANGE", strings.ToLower(hex.EncodeToString(keyHash[:])), "0", "-1")); err != nil { - return handleRekorAPIError(params, http.StatusInternalServerError, err, redisUnexpectedResult) + return handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("redis client: %w", err), redisUnexpectedResult) } result.Add(resultUUIDs) } if params.Query.Email != "" { var resultUUIDs []string if err := redisClient.Do(httpReqCtx, radix.Cmd(&resultUUIDs, "LRANGE", strings.ToLower(params.Query.Email.String()), "0", "-1")); err != nil { - return handleRekorAPIError(params, http.StatusInternalServerError, err, redisUnexpectedResult) + return handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("redis client: %w", err), redisUnexpectedResult) } result.Add(resultUUIDs) } @@ -100,7 +101,10 @@ func SearchIndexNotImplementedHandler(params index.SearchIndexParams) middleware } func addToIndex(ctx context.Context, key, value string) error { - return redisClient.Do(ctx, radix.Cmd(nil, "LPUSH", key, value)) + if err := redisClient.Do(ctx, radix.Cmd(nil, "LPUSH", key, value)); err != nil { + return fmt.Errorf("redis client: %w", err) + } + return nil } func storeAttestation(ctx context.Context, uuid string, attestation []byte) error {