{"record":{"id":"f36ee89baccb302f","repo":"grafana/k6","slug":"invalid-hostname-pattern-s","errorCode":null,"errorMessage":"invalid hostname pattern '%s'","messagePattern":"invalid hostname pattern '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/types/hostnametrie.go","lineNumber":117,"sourceCode":"\t}\n\tfor _, s := range h.source {\n\t\tif err := h.insert(s); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\treturn h, nil\n}\n\n// Regex description of hostname 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 validHostnamePattern = 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]))?$`)\n\nfunc isValidHostnamePattern(s string) error {\n\tif len(validHostnamePattern.FindString(s)) != len(s) {\n\t\treturn fmt.Errorf(\"invalid hostname pattern '%s'\", s)\n\t}\n\treturn nil\n}\n\n// insert inserts a hostname pattern into the HostnameTrie. It returns an error\n// if the hostname pattern is invalid.\nfunc (t *HostnameTrie) insert(s string) error {\n\ts = strings.ToLower(s)\n\tif err := isValidHostnamePattern(s); err != nil {\n\t\treturn err\n\t}\n\n\tt.trieNode.insert(s)\n\treturn nil\n}\n\n// Contains returns whether s matches a pattern in the HostnameTrie\n// along with the matching pattern, if one was found.","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/lib/types/hostnametrie.go#L99-L135","documentation":"Raised by isValidHostnamePattern when a hostnames/blockHostnames entry does not match the allowed hostname wildcard pattern (optional *. prefix plus dot-separated labels). It is a regex-based format guard for hostname trie entries.","triggerScenarios":"Thrown at lib/types/hostnametrie.go:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a plain hostname or a wildcard like *.example.com","Avoid patterns with multiple wildcards, paths, ports or invalid characters in hostnames"],"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-14T00:17:10.932Z"}