tsenart/vegeta · error

invalid -connect-to %q, expected format: %s

Error message

invalid -connect-to %q, expected format: %s

What it means

The -connect-to flag maps source host:port to destination host:port and is parsed by splitting on ':'. A valid entry must yield exactly 4 parts (host, port, host, port); anything else cannot be interpreted and is rejected with the expected format shown in connectToFormat.

Source

Thrown at flags.go:189

		addrMappings = append(addrMappings, k+":"+strings.Join(v, ","))
	}

	sort.Strings(addrMappings)
	return strings.Join(addrMappings, ";")
}

func (c *connectToFlag) Set(s string) error {
	if c.addrMap == nil {
		return nil
	}

	if *c.addrMap == nil {
		*c.addrMap = make(map[string][]string)
	}

	parts := strings.Split(s, ":")
	if len(parts) != 4 {
		return fmt.Errorf("invalid -connect-to %q, expected format: %s", s, connectToFormat)
	}
	srcAddr := parts[0] + ":" + parts[1]
	dstAddr := parts[2] + ":" + parts[3]

	// Parse source address
	if _, _, err := net.SplitHostPort(srcAddr); err != nil {
		return fmt.Errorf("invalid source address expression [%s], expected address:port", srcAddr)
	}

	// Parse destination address
	if _, _, err := net.SplitHostPort(dstAddr); err != nil {
		return fmt.Errorf("invalid destination address expression [%s], expected address:port", dstAddr)
	}

	(*c.addrMap)[srcAddr] = append((*c.addrMap)[srcAddr], dstAddr)

	return nil
}

View on GitHub (pinned to cf58112690)

Solutions

  1. Use exactly host:port:host:port, e.g. -connect-to=example.com:80:127.0.0.1:8080.
  2. Avoid raw IPv6 literals; use IPv4 or a form compatible with the 4-part split.
  3. Quote the flag value in the shell so colons are preserved.
  4. Validate the value has exactly three colons before invoking vegeta.

Example fix

// before
-connect-to=example.com:80
// after
-connect-to=example.com:80:localhost:8080
Defensive patterns

Strategy: validation

Validate before calling

func validConnectTo(s string) bool {
	parts := strings.Split(s, ":")
	if len(parts) != 4 {
		return false
	}
	_, _, err1 := net.SplitHostPort(parts[0] + ":" + parts[1])
	_, _, err2 := net.SplitHostPort(parts[2] + ":" + parts[3])
	return err1 == nil && err2 == nil
}

Prevention

When it happens

Trigger: Calling ConnectTo.Set (or -connect-to) with a value that does not split into exactly 4 ':'-separated parts, e.g. "example.com:80:localhost:8080:extra", a bare host, or an IPv6 literal whose extra colons break the count.

Common situations: Forgetting one of the two host:port halves; including an IPv6 address (colons inflate the part count); shell mangling of the value; trailing garbage from templating.

Related errors


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