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 err

View on GitHub (pinned to cf58112690)

Solutions

  1. Use one of the supported values for -to: gob, csv, or json.
  2. Check `vegeta encode -help` for the exact accepted encoding strings in your version.
  3. 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

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


AI-assisted analysis of tsenart/vegeta@cf58112690 (2026-08-31). Data as JSON: /api/errors/039658639aacd499. Report an issue: GitHub.