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

fix: improve errors for ReadAll and loadIndexfile #526

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion content/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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)
shizhMSFT marked this conversation as resolved.
Show resolved Hide resolved
}

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