{"record":{"id":"fa6db27b435067f5","repo":"grafana/k6","slug":"invalid-host-pattern-s","errorCode":null,"errorMessage":"invalid host pattern '%s'","messagePattern":"invalid host pattern '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/types/hosts.go","lineNumber":133,"sourceCode":"\nfunc toLowerKeys(source map[string]Host) map[string]Host {\n\tresult := make(map[string]Host, len(source))\n\tfor k, v := range source {\n\t\tresult[strings.ToLower(k)] = v\n\t}\n\treturn result\n}\n\n// Regex description of domain(:port)? pattern to enforce blocks by.\n// Global var to avoid compilation penalty at runtime.\n// Based on regex from https://stackoverflow.com/a/106223/5427244\n//\n//nolint:lll\nvar validHostPattern = regexp.MustCompile(`^(\\*\\.?)?((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9]))?(:[0-9]{1,5})?$`)\n\nfunc isValidHostPattern(s string) error {\n\tif len(validHostPattern.FindString(s)) != len(s) {\n\t\treturn fmt.Errorf(\"invalid host pattern '%s'\", s)\n\t}\n\treturn nil\n}\n\nfunc (t *Hosts) insert(s string) error {\n\ts = strings.ToLower(s) // domains are not case-sensitive\n\n\tif err := isValidHostPattern(s); err != nil {\n\t\treturn err\n\t}\n\n\tt.n.insert(s)\n\n\treturn nil\n}\n\n// Match returns the host matching s, where the value can be one of:\n// - nil (no match)","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/lib/types/hosts.go#L115-L151","documentation":"Raised by isValidHostPattern when a hosts entry key does not match the allowed host(:port) pattern — optional *. wildcard prefix, DNS labels, and an optional numeric port. It guards the --host override map keys.","triggerScenarios":"Thrown at lib/types/hosts.go:133 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use forms like example.com, *.example.com or example.com:8080","Remove invalid characters, schemes (http://) or paths from the host key"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}