Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
more accurate message when validating CAR header
Browse files Browse the repository at this point in the history
Signed-off-by: Merlin Ran <[email protected]>
  • Loading branch information
merlinran committed Jul 16, 2021
1 parent 6958941 commit ddfe0ac
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions service/datauri/datauri.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (u *HTTPURI) Validate(ctx context.Context) error {
return fmt.Errorf("http request returned bad status %d: %w", res.StatusCode, ErrCarFileUnavailable)
}

log.Debugf("validating car file uri: %s", u.uri)
log.Debugf("validating car file cid: %s", u.cid)
if _, err := validateCarHeader(u.cid, res.Body); err != nil {
return fmt.Errorf("validating car header: %w", err)
}
Expand All @@ -117,7 +117,7 @@ func (u *HTTPURI) Write(ctx context.Context, writer io.Writer) error {
return fmt.Errorf("http request returned bad status %d: %w", res.StatusCode, ErrCarFileUnavailable)
}

log.Debugf("validating car file uri: %s", u.uri)
log.Debugf("validating car file cid: %s", u.cid)
r, err := validateCarHeader(u.cid, res.Body)
if err != nil {
return fmt.Errorf("validating car header: %w", err)
Expand Down Expand Up @@ -163,7 +163,7 @@ func validateCarHeader(root cid.Cid, reader io.Reader) (io.Reader, error) {
return nil, fmt.Errorf("car file must have only one root: %w", ErrInvalidCarFile)
}
if !ch.Roots[0].Equals(root) {
return nil, fmt.Errorf("car file root does not match uri: %w", ErrInvalidCarFile)
return nil, fmt.Errorf("car file root does not match cid: %w", ErrInvalidCarFile)
}

return io.MultiReader(bytes.NewReader(phb), bytes.NewReader(hb), buf), nil
Expand Down

0 comments on commit ddfe0ac

Please sign in to comment.