From 18b0bbbf420131f8d6194fbbe89217a100934ff4 Mon Sep 17 00:00:00 2001
From: Michael Eischer <michael.eischer@fau.de>
Date: Sat, 17 Feb 2024 19:37:32 +0100
Subject: [PATCH 1/2] repository: use fmt.Errorf in StreamPacks

---
 internal/repository/repository.go | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/internal/repository/repository.go b/internal/repository/repository.go
index 9a4494c4d..87eb01367 100644
--- a/internal/repository/repository.go
+++ b/internal/repository/repository.go
@@ -1079,7 +1079,7 @@ func (b *PackBlobIterator) Next() (PackBlobValue, error) {
 
 	skipBytes := int(entry.Offset - b.currentOffset)
 	if skipBytes < 0 {
-		return PackBlobValue{}, errors.Errorf("overlapping blobs in pack %v", b.packID)
+		return PackBlobValue{}, fmt.Errorf("overlapping blobs in pack %v", b.packID)
 	}
 
 	_, err := b.rd.Discard(skipBytes)
@@ -1099,18 +1099,18 @@ func (b *PackBlobIterator) Next() (PackBlobValue, error) {
 	n, err := io.ReadFull(b.rd, b.buf)
 	if err != nil {
 		debug.Log("    read error %v", err)
-		return PackBlobValue{}, errors.Wrap(err, "ReadFull")
+		return PackBlobValue{}, fmt.Errorf("readFull: %w", err)
 	}
 
 	if n != len(b.buf) {
-		return PackBlobValue{}, errors.Errorf("read blob %v from %v: not enough bytes read, want %v, got %v",
+		return PackBlobValue{}, fmt.Errorf("read blob %v from %v: not enough bytes read, want %v, got %v",
 			h, b.packID.Str(), len(b.buf), n)
 	}
 	b.currentOffset = entry.Offset + entry.Length
 
 	if int(entry.Length) <= b.key.NonceSize() {
 		debug.Log("%v", b.blobs)
-		return PackBlobValue{}, errors.Errorf("invalid blob length %v", entry)
+		return PackBlobValue{}, fmt.Errorf("invalid blob length %v", entry)
 	}
 
 	// decryption errors are likely permanent, give the caller a chance to skip them
@@ -1130,7 +1130,7 @@ func (b *PackBlobIterator) Next() (PackBlobValue, error) {
 		if !id.Equal(entry.ID) {
 			debug.Log("read blob %v/%v from %v: wrong data returned, hash is %v",
 				h.Type, h.ID, b.packID.Str(), id)
-			err = errors.Errorf("read blob %v from %v: wrong data returned, hash is %v",
+			err = fmt.Errorf("read blob %v from %v: wrong data returned, hash is %v",
 				h, b.packID.Str(), id)
 		}
 	}

From 4c3218ef9f35e6a8336a096e45d5df7b57244bc4 Mon Sep 17 00:00:00 2001
From: Michael Eischer <michael.eischer@fau.de>
Date: Sat, 17 Feb 2024 19:38:01 +0100
Subject: [PATCH 2/2] repository: include packID in StreamPack for
 decrypt/decompress errors

---
 internal/repository/repository.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/internal/repository/repository.go b/internal/repository/repository.go
index 87eb01367..8e34c7125 100644
--- a/internal/repository/repository.go
+++ b/internal/repository/repository.go
@@ -1116,13 +1116,16 @@ func (b *PackBlobIterator) Next() (PackBlobValue, error) {
 	// decryption errors are likely permanent, give the caller a chance to skip them
 	nonce, ciphertext := b.buf[:b.key.NonceSize()], b.buf[b.key.NonceSize():]
 	plaintext, err := b.key.Open(ciphertext[:0], nonce, ciphertext, nil)
+	if err != nil {
+		err = fmt.Errorf("decrypting blob %v from %v failed: %w", h, b.packID.Str(), err)
+	}
 	if err == nil && entry.IsCompressed() {
 		// DecodeAll will allocate a slice if it is not large enough since it
 		// knows the decompressed size (because we're using EncodeAll)
 		b.decode, err = b.dec.DecodeAll(plaintext, b.decode[:0])
 		plaintext = b.decode
 		if err != nil {
-			err = errors.Errorf("decompressing blob %v failed: %v", h, err)
+			err = fmt.Errorf("decompressing blob %v from %v failed: %w", h, b.packID.Str(), err)
 		}
 	}
 	if err == nil {