tsenart/vegeta · error
bad buckets: %s
Error message
bad buckets: %s
What it means
vegeta's Buckets type (used by -buckets for histogram reporting) implements encoding.TextUnmarshaler and requires the literal format "[d1,d2,...]" — starting with '[' and ending with ']' and at least two characters. Any value not shaped like a bracketed list is rejected with this error before durations are parsed.
Source
Thrown at lib/histogram.go:69
}
}
buf.WriteString("}")
return buf.Bytes(), nil
}
// Nth returns the nth bucket represented as a string.
func (bs Buckets) Nth(i int) (left, right string) {
if i >= len(bs)-1 {
return bs[i].String(), "+Inf"
}
return bs[i].String(), bs[i+1].String()
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (bs *Buckets) UnmarshalText(value []byte) error {
if len(value) < 2 || value[0] != '[' || value[len(value)-1] != ']' {
return fmt.Errorf("bad buckets: %s", value)
}
for i, v := range strings.Split(string(value[1:len(value)-1]), ",") {
d, err := time.ParseDuration(strings.TrimSpace(v))
if err != nil {
return err
}
// add a default range of [0-Buckets[0]) if needed
if i == 0 && d > 0 {
*bs = append(*bs, 0)
}
*bs = append(*bs, d)
}
if len(*bs) == 0 {
return fmt.Errorf("bad buckets: %s", value)
}
return nil
}
View on GitHub (pinned to cf58112690)
Solutions
- Wrap the durations in brackets: -buckets='[100ms,200ms,1s]'.
- Quote the value in the shell so brackets are not glob-expanded or stripped.
- Ensure the value has at least 2 characters (non-empty "[]").
- After the format, verify each entry parses as a Go duration (100ms, 2s, 1m...).
Example fix
// before vegeta report -buckets=100ms,200ms results.bin // after vegeta report -buckets='[100ms,200ms]' results.bin
Defensive patterns
Strategy: validation
Validate before calling
func validBuckets(s string) bool {
if len(s) < 2 || s[0] != '[' || s[len(s)-1] != ']' {
return false
}
for _, v := range strings.Split(s[1:len(s)-1], ",") {
if _, err := time.ParseDuration(strings.TrimSpace(v)); err != nil {
return false
}
}
return true
} Prevention
- Always wrap bucket lists in brackets: '[100ms,200ms]'.
- Quote the flag value in the shell to protect brackets.
- Ensure each entry is a valid Go duration with a unit.
- Pre-validate with the validBuckets helper in wrappers.
When it happens
Trigger: Calling Buckets.UnmarshalText (directly or via the -buckets flag's Set) with a value that is empty, a single character, or not wrapped in brackets — e.g. "100ms,200ms".
Common situations: Forgetting the surrounding brackets on the CLI; the shell eating the brackets (unquoted); passing a plain comma list copied from documentation prose.
Related errors
- -rate format %q doesn't match the "freq/duration" format (i.
- -max-body=%d overflows int64
- invalid -connect-to %q, expected format: %s
- -rate=0 requires setting -max-workers
- error opening %s: %s
AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31).
Data as JSON: /api/errors/6f1327fbc1bc2ebe.
Report an issue: GitHub.