Skip to content

Commit

Permalink
Improve error handling a bit
Browse files Browse the repository at this point in the history
Include more details in the returned error text.

Don't continue in tests when we fail to obtain a TOC.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Apr 24, 2024
1 parent ee01064 commit 791869f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/chunked/compression_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di

decodedBlob, err := decodeAndValidateBlob(manifest, manifestLengthUncompressed, tocDigest.String())
if err != nil {
return nil, nil, nil, 0, err
return nil, nil, nil, 0, fmt.Errorf("validating and decompressing TOC: %w", err)
}
toc, err := unmarshalToc(decodedBlob)
if err != nil {
Expand All @@ -217,7 +217,7 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di

decodedTarSplit, err = decodeAndValidateBlob(tarSplit, tarSplitLengthUncompressed, toc.TarSplitDigest.String())
if err != nil {
return nil, nil, nil, 0, err
return nil, nil, nil, 0, fmt.Errorf("validating and decompressing tar-split: %w", err)
}
}
return decodedBlob, toc, decodedTarSplit, int64(manifestChunk.Offset), err
Expand All @@ -226,7 +226,7 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di
func decodeAndValidateBlob(blob []byte, lengthUncompressed uint64, expectedCompressedChecksum string) ([]byte, error) {
d, err := digest.Parse(expectedCompressedChecksum)
if err != nil {
return nil, err
return nil, fmt.Errorf("invalid digest %q: %w", expectedCompressedChecksum, err)
}

blobDigester := d.Algorithm().Digester()
Expand Down
4 changes: 1 addition & 3 deletions pkg/chunked/zstdchunked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ func TestGenerateAndParseManifest(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, tocDigest)
manifest, decodedTOC, _, _, err := readZstdChunkedManifest(s, *tocDigest, annotations)
if err != nil {
t.Error(err)
}
require.NoError(t, err)

var toc internal.TOC
if err := json.Unmarshal(manifest, &toc); err != nil {
Expand Down

0 comments on commit 791869f

Please sign in to comment.