Skip to content

Commit 074bbee

Browse files
bborehamgouthamve
authored andcommitted
Improve reporting of some chunk errors (#1789)
%q is better than '%v' because it will show unprintable characters as escape sequences. Signed-off-by: Bryan Boreham <[email protected]>
1 parent 416ecdc commit 074bbee

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

pkg/chunk/chunk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (c *Chunk) Decode(decodeContext *DecodeContext, input []byte) error {
291291
metadataRead := len(input) - r.Len()
292292
// Older versions of Cortex included the initial length word; newer versions do not.
293293
if !(metadataRead == int(metadataLen) || metadataRead == int(metadataLen)+4) {
294-
return ErrMetadataLength
294+
return errors.Wrapf(ErrMetadataLength, "expected %d, got %d", metadataLen, metadataRead)
295295
}
296296

297297
// Next, confirm the chunks matches what we expected. Easiest way to do this

pkg/chunk/schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func parseRangeValueType(rangeValue []byte) (int, error) {
171171
return SeriesRangeValue, nil
172172

173173
default:
174-
return 0, fmt.Errorf("unrecognised range value type. version: '%v'", string(components[3]))
174+
return 0, fmt.Errorf("unrecognised range value type. version: %q", string(components[3]))
175175
}
176176
}
177177

pkg/chunk/schema_util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func parseMetricNameRangeValue(rangeValue []byte, value []byte) (model.LabelValu
139139
return model.LabelValue(value), nil
140140

141141
default:
142-
return "", fmt.Errorf("unrecognised metricNameRangeKey version: '%v'", string(components[3]))
142+
return "", fmt.Errorf("unrecognised metricNameRangeKey version: %q", string(components[3]))
143143
}
144144
}
145145

@@ -160,7 +160,7 @@ func parseSeriesRangeValue(rangeValue []byte, value []byte) (model.Metric, error
160160
return series, nil
161161

162162
default:
163-
return nil, fmt.Errorf("unrecognised seriesRangeKey version: '%v'", string(components[3]))
163+
return nil, fmt.Errorf("unrecognised seriesRangeKey version: %q", string(components[3]))
164164
}
165165
}
166166

@@ -232,7 +232,7 @@ func parseChunkTimeRangeValue(rangeValue []byte, value []byte) (
232232
return
233233

234234
default:
235-
err = fmt.Errorf("unrecognised chunkTimeRangeKey version: '%v'", string(components[3]))
235+
err = fmt.Errorf("unrecognised chunkTimeRangeKey version: %q", string(components[3]))
236236
return
237237
}
238238
}

0 commit comments

Comments
 (0)