From 791869f6a1bf58681dd16ee2ad22a812893eba75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Tue, 23 Apr 2024 22:55:36 +0200 Subject: [PATCH] Improve error handling a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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č --- pkg/chunked/compression_linux.go | 6 +++--- pkg/chunked/zstdchunked_test.go | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/chunked/compression_linux.go b/pkg/chunked/compression_linux.go index 5b2c556725..7b3879a994 100644 --- a/pkg/chunked/compression_linux.go +++ b/pkg/chunked/compression_linux.go @@ -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 { @@ -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 @@ -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() diff --git a/pkg/chunked/zstdchunked_test.go b/pkg/chunked/zstdchunked_test.go index 63f1ad82b1..ef12076799 100644 --- a/pkg/chunked/zstdchunked_test.go +++ b/pkg/chunked/zstdchunked_test.go @@ -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 {