Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass transient errors through retrieveLogEntry #1653

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,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)
}
Expand Down Expand Up @@ -569,7 +569,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
}
Expand All @@ -594,14 +597,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

Expand Down