Skip to content

Commit

Permalink
Improve errors for ReadAll and loadIndexfile
Browse files Browse the repository at this point in the history
Signed-off-by: Clarence "Sparr" Risher <clrnc@amazon.com>
  • Loading branch information
sparr committed Jun 20, 2023
1 parent 7dd0378 commit 5ef63f4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewWithContext(ctx context.Context, root string) (*Store, error) {
return nil, fmt.Errorf("invalid OCI Image Layout: %w", err)
}
if err := store.loadIndexFile(ctx); err != nil {
return nil, fmt.Errorf("invalid OCI Image Layout: %w", err)
return nil, fmt.Errorf("invalid OCI Image Index: %w", err)
}

return store, nil
Expand Down
2 changes: 1 addition & 1 deletion content/oci/readonlyoci.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewFromFS(ctx context.Context, fsys fs.FS) (*ReadOnlyStore, error) {
return nil, fmt.Errorf("invalid OCI Image Layout: %w", err)
}
if err := store.loadIndexFile(ctx); err != nil {
return nil, fmt.Errorf("invalid OCI Image Layout: %w", err)
return nil, fmt.Errorf("invalid OCI Image Index: %w", err)
}

return store, nil
Expand Down
7 changes: 5 additions & 2 deletions content/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (vr *VerifyReader) Read(p []byte) (n int, err error) {
return
}

// Verify verifies the read content against the size and the digest.
// Verify checks for remaining unread content and verifies the read content against the digest
func (vr *VerifyReader) Verify() error {
if vr.verified {
return nil
Expand Down Expand Up @@ -120,7 +120,10 @@ func ReadAll(r io.Reader, desc ocispec.Descriptor) ([]byte, error) {
buf := make([]byte, desc.Size)

vr := NewVerifyReader(r, desc)
if _, err := io.ReadFull(vr, buf); err != nil {
if n, err := io.ReadFull(vr, buf); err != nil {
if errors.Is(err, io.ErrUnexpectedEOF) {
return nil, fmt.Errorf("read failed, expected content size of %d, got %d, for digest %s: %w", desc.Size, n, desc.Digest.String(), err)
}
return nil, fmt.Errorf("read failed: %w", err)
}
if err := vr.Verify(); err != nil {
Expand Down

0 comments on commit 5ef63f4

Please sign in to comment.