tsenart/vegeta · error

-rate format %q doesn't match the "freq/duration" format (i.

Error message

-rate format %q doesn't match the "freq/duration" format (i.e. 50/1s)

What it means

vegeta's Rate flag parses '-rate' as freq/duration. strings.SplitN(v,"/",2) yielding 0 parts (an empty -rate value) means the value cannot match the documented "freq/duration" format, so Set rejects it with this message.

Source

Thrown at flags.go:79

	*l = strings.Split(v, ",")
	return nil
}

func (l csl) String() string { return strings.Join(l, ",") }

type rateFlag struct{ *vegeta.Rate }

func (f *rateFlag) Set(v string) (err error) {
	if v == "infinity" {
		return nil
	}

	ps := strings.SplitN(v, "/", 2)
	switch len(ps) {
	case 1:
		ps = append(ps, "1s")
	case 0:
		return fmt.Errorf("-rate format %q doesn't match the \"freq/duration\" format (i.e. 50/1s)", v)
	}

	f.Freq, err = strconv.Atoi(ps[0])
	if err != nil {
		return err
	}

	if f.Freq == 0 {
		return nil
	}

	switch ps[1] {
	case "ns", "us", "µs", "ms", "s", "m", "h":
		ps[1] = "1" + ps[1]
	}

	f.Per, err = time.ParseDuration(ps[1])
	return err

View on GitHub (pinned to cf58112690)

Solutions

  1. Supply a value in "freq/duration" form, e.g. -rate=50/1s.
  2. Use the shorthand -rate=50, which defaults the duration to 1s.
  3. In scripts, guard against empty variables: ${RATE:-50/1s}.
  4. Note Atoi errors on the freq part produce a different error; this one is specifically for an empty value.

Example fix

// before
vegeta attack -rate=$RATE ...   # RATE unset -> empty
// after
vegeta attack -rate=50/1s ...
Defensive patterns

Strategy: validation

Validate before calling

func validRate(s string) bool {
	if s == "" {
		return false
	}
	parts := strings.SplitN(s, "/", 2)
	if _, err := strconv.Atoi(parts[0]); err != nil {
		return false
	}
	if len(parts) == 2 {
		if _, err := time.ParseDuration(parts[1]); err != nil {
			return false
		}
	}
	return true
}

Prevention

When it happens

Trigger: Passing an empty string to the -rate flag (e.g. -rate="" or an unbound shell variable expanding to nothing), so the split produces zero parts.

Common situations: Scripted invocations where a RATE variable is unset/empty; config templating leaving the flag blank; copy-pasted examples that omit the value.

Related errors


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