k3s-io/k3s · error

invalid output format:

Error message

invalid output format: 

What it means

`k3s etcd-snapshot list` accepts an output format via the list-format flag; validEtcdListFormat compares it against the fixed set {json, yaml, table}. Any other non-empty value fails immediately with this error before the list request is dispatched.

Source

Thrown at pkg/cli/etcdsnapshot/etcd_snapshot.go:214

		return err
	}
	return list(app, &cmds.ServerConfig)
}

var etcdListFormats = []string{"json", "yaml", "table"}

func validEtcdListFormat(format string) bool {
	for _, supportedFormat := range etcdListFormats {
		if format == supportedFormat {
			return true
		}
	}
	return false
}

func list(app *cli.Context, cfg *cmds.Server) error {
	if cfg.EtcdListFormat != "" && !validEtcdListFormat(cfg.EtcdListFormat) {
		return errors.New("invalid output format: " + cfg.EtcdListFormat)
	}

	sr, info, err := commandSetup(app, cfg)
	if err != nil {
		return err
	}

	sr.Operation = etcd.SnapshotOperationList

	b, err := json.Marshal(sr)
	if err != nil {
		return err
	}
	r, err := info.Post("/db/snapshot", b, clientaccess.WithTimeout(timeout))
	if err != nil {
		return wrapServerError(err)
	}

View on GitHub (pinned to 6ba341e396)

Solutions

  1. Use one of the supported values exactly: --format json, --format yaml, or --format table (default)
  2. Fix case: JSON is rejected; use lowercase json
  3. For machine consumption prefer json and pipe to jq

Example fix

# before
k3s etcd-snapshot list --format JSON  # -> invalid output format: JSON

# after
k3s etcd-snapshot list --format json | jq .
Defensive patterns

Strategy: validation

Validate before calling

func validFormat(f string) bool {
    switch f { case "", "json", "yaml", "table": return true; default: return false }
}
if !validFormat(cfg.EtcdListFormat) {
    return fmt.Errorf("unsupported --format %q; use json, yaml, or table", cfg.EtcdListFormat)
}

Type guard

func isEtcdListFormat(f string) bool { return slices.Contains([]string{"json", "yaml", "table"}, f) }

Prevention

When it happens

Trigger: Passing --format json|yaml|table with a typo or unsupported value: --format=JSON (case-sensitive), --format=custom, --format=name.

Common situations: Scripts assuming case-insensitive or extra formats (e.g. wide, custom-columns); CI parsing expecting a format k3s never supported; tab-completion inserting a wrong value.

Related errors


AI-assisted analysis of k3s-io/k3s@6ba341e396 (2026-08-15). Data as JSON: /api/errors/f5f0a4230a86bdee. Report an issue: GitHub.