Skip to content

Commit

Permalink
wrap redis client errors to aid debugging
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Callaway <bcallaway@google.com>
  • Loading branch information
bobcallaway committed Nov 4, 2022
1 parent 7412e93 commit 9244079
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/api/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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 {
Expand Down

0 comments on commit 9244079

Please sign in to comment.