{"record":{"id":"8bf84cb3890e3de4","repo":"grafana/k6","slug":"negative-ip-range-s","errorCode":null,"errorMessage":"negative IP range: %s","messagePattern":"negative IP range: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/types/ipblock.go","lineNumber":55,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"%s is not a valid IP, IP range or CIDR\", s)\n\t\t}\n\t\treturn ipBlockFromRange(s + \"-\" + s)\n\t}\n}\n\nfunc ipBlockFromRange(s string) (*ipBlock, error) {\n\tip0Str, ip1Str, _ := strings.Cut(s, \"-\")\n\tip0, ip1 := net.ParseIP(ip0Str), net.ParseIP(ip1Str)\n\tif ip0 == nil || ip1 == nil {\n\t\treturn nil, errors.New(\"wrong IP range format: \" + s)\n\t}\n\tif (ip0.To4() == nil) != (ip1.To4() == nil) { // XOR\n\t\treturn nil, errors.New(\"mixed IP range format: \" + s)\n\t}\n\tblock := ipBlockFromTwoIPs(ip0, ip1)\n\n\tif block.count.Sign() <= 0 {\n\t\treturn nil, errors.New(\"negative IP range: \" + s)\n\t}\n\treturn block, nil\n}\n\nfunc ipBlockFromTwoIPs(ip0, ip1 net.IP) *ipBlock {\n\t// This code doesn't do any checks on the validity of the arguments, that should be\n\t// done before and/or after it is called\n\tvar block ipBlock\n\tblock.firstIP = new(big.Int)\n\tblock.count = new(big.Int)\n\tblock.ipv6 = ip0.To4() == nil\n\tif block.ipv6 {\n\t\tblock.firstIP.SetBytes(ip0.To16())\n\t\tblock.count.SetBytes(ip1.To16())\n\t} else {\n\t\tblock.firstIP.SetBytes(ip0.To4())\n\t\tblock.count.SetBytes(ip1.To4())\n\t}","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/lib/types/ipblock.go#L37-L73","documentation":"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.","triggerScenarios":"Thrown at lib/types/ipblock.go:55 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}