grafana/k6 · error

wrong IP range format

Error message

wrong IP range format: %s

What it means

Raised by ipBlockFromRange when parsing the 'startIP-endIP' form of an IP range: at least one side of the '-' failed net.ParseIP, so the string is not two valid IP addresses. Reached via getIPBlock when configuring a blackspot/IP block from a range expression.

Solutions

  1. Use two valid IPs around the dash, e.g. '192.168.0.1-192.168.0.255'
  2. Pass a single IP (expanded to a one-IP range) or a CIDR like '10.0.0.0/8' instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/types/ipblock.go:47 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/be70eb5f3da7d778. Report an issue: GitHub.

Appendix: source

Thrown at lib/types/ipblock.go:47

func getIPBlock(s string) (*ipBlock, error) {
	switch {
	case strings.Contains(s, "-"):
		return ipBlockFromRange(s)
	case strings.Contains(s, "/"):
		return ipBlockFromCIDR(s)
	default:
		if net.ParseIP(s) == nil {
			return nil, fmt.Errorf("%s is not a valid IP, IP range or CIDR", s)
		}
		return ipBlockFromRange(s + "-" + s)
	}
}

func ipBlockFromRange(s string) (*ipBlock, error) {
	ip0Str, ip1Str, _ := strings.Cut(s, "-")
	ip0, ip1 := net.ParseIP(ip0Str), net.ParseIP(ip1Str)
	if ip0 == nil || ip1 == nil {
		return nil, errors.New("wrong IP range format: " + s)
	}
	if (ip0.To4() == nil) != (ip1.To4() == nil) { // XOR
		return nil, errors.New("mixed IP range format: " + s)
	}
	block := ipBlockFromTwoIPs(ip0, ip1)

	if block.count.Sign() <= 0 {
		return nil, errors.New("negative IP range: " + s)
	}
	return block, nil
}

func ipBlockFromTwoIPs(ip0, ip1 net.IP) *ipBlock {
	// This code doesn't do any checks on the validity of the arguments, that should be
	// done before and/or after it is called
	var block ipBlock
	block.firstIP = new(big.Int)
	block.count = new(big.Int)

View on GitHub (pinned to 01ffac6f24)