grafana/k6 · error

parseCIDR() failed parsing %s: %w

Error message

parseCIDR() failed parsing %s: %w

What it means

Raised by ipBlockFromCIDR when net.ParseCIDR rejects the CIDR string; the underlying Go error is wrapped with %w. Reached only when the input contains '/' but is not well-formed CIDR notation.

Source

Thrown at lib/types/ipblock.go:83

	block.count = new(big.Int)
	block.ipv6 = ip0.To4() == nil
	if block.ipv6 {
		block.firstIP.SetBytes(ip0.To16())
		block.count.SetBytes(ip1.To16())
	} else {
		block.firstIP.SetBytes(ip0.To4())
		block.count.SetBytes(ip1.To4())
	}
	block.count.Sub(block.count, block.firstIP)
	block.count.Add(block.count, big.NewInt(1))

	return &block
}

func ipBlockFromCIDR(s string) (*ipBlock, error) {
	_, pnet, err := net.ParseCIDR(s)
	if err != nil {
		return nil, fmt.Errorf("parseCIDR() failed parsing %s: %w", s, err)
	}
	ip0 := pnet.IP
	// TODO: this is just to copy it, it will probably be better to copy the bytes ...
	ip1 := net.ParseIP(ip0.String())
	if ip1.To4() == nil {
		ip1 = ip1.To16()
	} else {
		ip1 = ip1.To4()
	}
	for i := range ip1 {
		ip1[i] |= (255 ^ pnet.Mask[i])
	}
	block := ipBlockFromTwoIPs(ip0, ip1)
	// in the case of ipv4 if the network is bigger than 31 the first and last IP are reserved so we
	// need to reduce the addresses by 2 and increment the first ip
	if !block.ipv6 && big.NewInt(2).Cmp(block.count) < 0 {
		block.count.Sub(block.count, big.NewInt(2))
		block.firstIP.Add(block.firstIP, big.NewInt(1))

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use correct CIDR notation such as 10.0.0.0/8 or 2001:db8::/32
  2. Ensure the prefix length is valid for the IP version
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/types/ipblock.go:83 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/7efdc3502f6a21cd. Report an issue: GitHub.