From 4c6df3ebdd97574a94f4f412af93c836203999f5 Mon Sep 17 00:00:00 2001 From: Bob Callaway Date: Tue, 29 Aug 2023 16:54:36 -0600 Subject: [PATCH] pass transient errors through retrieveLogEntry (#1653) * pass transient errors through retrieveLogEntry Signed-off-by: Bob Callaway * fix lint error Signed-off-by: Bob Callaway --------- Signed-off-by: Bob Callaway --- pkg/api/entries.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/api/entries.go b/pkg/api/entries.go index 76dffe953..49643e4ce 100644 --- a/pkg/api/entries.go +++ b/pkg/api/entries.go @@ -410,7 +410,7 @@ func GetLogEntryByUUIDHandler(params entries.GetLogEntryByUUIDParams) middleware if _, ok := (err).(types.ValidationError); ok { return handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf("incorrectly formatted uuid %s", params.EntryUUID), params.EntryUUID) } - return handleRekorAPIError(params, http.StatusInternalServerError, err, "ID %s not found in any known trees", params.EntryUUID) + return handleRekorAPIError(params, http.StatusInternalServerError, err, trillianCommunicationError) } return entries.NewGetLogEntryByUUIDOK().WithPayload(logEntry) } @@ -576,7 +576,10 @@ func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, e for _, t := range trees { logEntry, err := retrieveUUIDFromTree(ctx, uuid, t.TreeID) if err != nil { - continue + if errors.Is(err, ErrNotFound) { + continue + } + return nil, err } return logEntry, nil } @@ -601,14 +604,18 @@ func retrieveUUIDFromTree(ctx context.Context, uuid string, tid int64) (models.L switch resp.Status { case codes.OK: result := resp.GetLeafAndProofResult - leaf := result.Leaf - if leaf == nil { - return models.LogEntry{}, ErrNotFound + if resp.Err != nil { + // this shouldn't be possible since GetLeafAndProofByHash verifies the inclusion proof using a computed leaf hash + // so this is just a defensive check + if result.Leaf == nil { + return models.LogEntry{}, ErrNotFound + } + return models.LogEntry{}, err } - logEntry, err := logEntryFromLeaf(ctx, api.signer, tc, leaf, result.SignedLogRoot, result.Proof, tid, api.logRanges) + logEntry, err := logEntryFromLeaf(ctx, api.signer, tc, result.Leaf, result.SignedLogRoot, result.Proof, tid, api.logRanges) if err != nil { - return models.LogEntry{}, errors.New("could not create log entry from leaf") + return models.LogEntry{}, fmt.Errorf("could not create log entry from leaf: %w", err) } return logEntry, nil