Skip to content

Commit afb73bc

Browse files
committed
Include the chunk ID that caused an error
otherwise the error can be very frustrating. We don't need an explicit WithStack() now we call errors.Errorf(). Signed-off-by: Bryan Boreham <bryan@weave.works>
1 parent 9f8d231 commit afb73bc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/chunk/chunk.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ import (
2525

2626
// Errors that decode can return
2727
const (
28-
ErrInvalidChunkID = errs.Error("invalid chunk ID")
2928
ErrInvalidChecksum = errs.Error("invalid chunk checksum")
3029
ErrWrongMetadata = errs.Error("wrong chunk metadata")
3130
ErrMetadataLength = errs.Error("chunk metadata wrong length")
3231
)
3332

3433
var castagnoliTable = crc32.MakeTable(crc32.Castagnoli)
3534

35+
func errInvalidChunkID(s string) error {
36+
return errors.Errorf("invalid chunk ID %q", s)
37+
}
38+
3639
// Chunk contains encoded timeseries data
3740
type Chunk struct {
3841
// These two fields will be missing from older chunks (as will the hash).
@@ -107,7 +110,7 @@ func ParseExternalKey(userID, externalKey string) (Chunk, error) {
107110
func parseLegacyChunkID(userID, key string) (Chunk, error) {
108111
parts := strings.Split(key, ":")
109112
if len(parts) != 3 {
110-
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
113+
return Chunk{}, errInvalidChunkID(key)
111114
}
112115
fingerprint, err := strconv.ParseUint(parts[0], 10, 64)
113116
if err != nil {
@@ -132,12 +135,12 @@ func parseLegacyChunkID(userID, key string) (Chunk, error) {
132135
func parseNewExternalKey(key string) (Chunk, error) {
133136
parts := strings.Split(key, "/")
134137
if len(parts) != 2 {
135-
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
138+
return Chunk{}, errInvalidChunkID(key)
136139
}
137140
userID := parts[0]
138141
hexParts := strings.Split(parts[1], ":")
139142
if len(hexParts) != 4 {
140-
return Chunk{}, errors.WithStack(ErrInvalidChunkID)
143+
return Chunk{}, errInvalidChunkID(key)
141144
}
142145
fingerprint, err := strconv.ParseUint(hexParts[0], 16, 64)
143146
if err != nil {

0 commit comments

Comments
 (0)