tsenart/vegeta · error
encode: can't detect encoding of %q
Error message
encode: can't detect encoding of %q
What it means
decoder() (in file.go) sniffs the encoding of each input file using vegeta.DecoderFor; if it cannot detect a known encoding (gob, csv, json) it returns this error with the filename. It is raised by encode, plotRun, and report whenever their input results file(s) are in an unrecognized format.
Source
Thrown at file.go:38
if create {
return os.Create(name)
}
return os.Open(name)
}
}
func decoder(files []string) (vegeta.Decoder, io.Closer, error) {
closer := make(multiCloser, 0, len(files))
decs := make([]vegeta.Decoder, 0, len(files))
for _, f := range files {
rc, err := file(f, false)
if err != nil {
return nil, closer, err
}
dec := vegeta.DecoderFor(rc)
if dec == nil {
return nil, closer, fmt.Errorf("encode: can't detect encoding of %q", f)
}
decs = append(decs, dec)
closer = append(closer, rc)
}
return vegeta.NewRoundRobinDecoder(decs...), closer, nil
}
type multiCloser []io.Closer
func (mc multiCloser) Close() error {
var errs []string
for _, c := range mc {
if err := c.Close(); err != nil {
errs = append(errs, err.Error())
}
}
View on GitHub (pinned to cf58112690)
Solutions
- Check the file is non-empty and is a vegeta results file (gob, csv, or json) — `file <path>` and inspect the head.
- Regenerate the results with `vegeta attack -output=results.bin` and pass that file as input.
- If the data is in another format, convert it to one of gob/csv/json first; ensure the correct extension-free content (DecoderFor sniffs content, not names).
Example fix
// before vegeta report output.txt # actually a plain log, not results // after vegeta attack -output=results.bin -duration=10s ... vegeta report results.bin
Defensive patterns
Strategy: validation
Validate before calling
st, err := os.Stat(path)
if err != nil || st.Size() == 0 {
return fmt.Errorf("input %q missing or empty", path)
}
// ensure the file is a vegeta results file (gob/csv/json), not logs or targets
head, _ := readHead(path, 16)
if !looksLikeGobCSVOrJSON(head) {
return fmt.Errorf("input %q is not a vegeta results file", path)
} Prevention
- Only feed attack output files (-output results) to report/plot/encode.
- Verify inputs are non-empty after long runs; an aborted attack can produce empty files.
- Do not pass log files, HTML error pages, or targets files as results inputs.
When it happens
Trigger: Passing an input file (-inputs / results file) that is empty, truncated, or not in gob/csv/json result format — e.g. an HTML error page saved by a failed curl, a log file, or a partially written results file.
Common situations: Feeding `vegeta report`/`plot` a file that was actually stdout text, not attack output; corrupted or zero-byte results from an aborted attack; piping results through a transform that changed the format; giving -inputs a targets file by mistake.
Related errors
- -rate=0 requires setting -max-workers
- format %q isn't one of [%s]
- encode: unknown encoding %q
- header '%s' has a wrong format
- rate frequency and time unit must be bigger than zero
AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31).
Data as JSON: /api/errors/4423d11928f9f186.
Report an issue: GitHub.