tsenart/vegeta · error
encode: unknown encoding %q
Error message
encode: unknown encoding %q
What it means
`vegeta encode` writes results in the encoding chosen by the -to flag; only gob, csv, and json are recognized. An unknown -to value reaches the default branch and returns this error naming the bad encoding.
Source
Thrown at encode.go:97
return err
}
out, err := file(output, true)
if err != nil {
return err
}
defer out.Close()
var enc vegeta.Encoder
switch to {
case encodingCSV:
enc = vegeta.NewCSVEncoder(out)
case encodingGob:
enc = vegeta.NewEncoder(out)
case encodingJSON:
enc = vegeta.NewJSONEncoder(out)
default:
return fmt.Errorf("encode: unknown encoding %q", to)
}
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, os.Interrupt)
for {
select {
case <-sigch:
return nil
default:
}
var r vegeta.Result
if err = dec.Decode(&r); err != nil {
if err == io.EOF {
break
}
return errView on GitHub (pinned to cf58112690)
Solutions
- Use one of the supported values for -to: gob, csv, or json.
- Check `vegeta encode -help` for the exact accepted encoding strings in your version.
- Quote/trim the shell variable feeding -to so it contains exactly the encoding name.
Example fix
// before vegeta encode -to=yaml < results.gob // after vegeta encode -to=json < results.gob
Defensive patterns
Strategy: validation
Validate before calling
var validEncodings = map[string]bool{"gob": true, "csv": true, "json": true}
if !validEncodings[to] {
return fmt.Errorf("-to %q invalid; use gob, csv or json", to)
} Prevention
- Use only gob, csv, json for -to.
- Trim/validate shell variables before interpolating into CLI flags.
- Check `vegeta encode -help` after upgrades for accepted values.
When it happens
Trigger: `vegeta encode -to=<unsupported>`, e.g. `-to=yaml`, `-to=`, or a typo like `-to=jso n` / `-to=JSON` if matching is case-sensitive in the caller's flags.
Common situations: Users assuming arbitrary encodings are supported; shell variables with empty or mis-typed encoding values; legacy scripts using formats from other tools.
Related errors
- format %q isn't one of [%s]
- -rate=0 requires setting -max-workers
- rate frequency and time unit must be bigger than zero
- encode: can't detect encoding of %q
- header '%s' has a wrong format
AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31).
Data as JSON: /api/errors/039658639aacd499.
Report an issue: GitHub.