grafana/k6 · error
negative IP range
Error message
negative IP range: %s
What it means
Raised by ipBlockFromRange when the range is technically valid but its start IP is greater than its end IP, yielding a zero or negative address count in the computed ipBlock.
Solutions
- Swap the boundaries so the smaller IP comes first, e.g. '10.0.0.1-10.0.0.5' instead of the reverse
- For a single address, pass just the IP without a dash
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/types/ipblock.go:55 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/8bf84cb3890e3de4.
Report an issue: GitHub.
Appendix: source
Thrown at lib/types/ipblock.go:55
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)
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())
}View on GitHub (pinned to 01ffac6f24)