grafana/k6 · error
invalid host pattern '%s'
Error message
invalid host pattern '%s'
What it means
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.
Source
Thrown at lib/types/hosts.go:133
func toLowerKeys(source map[string]Host) map[string]Host {
result := make(map[string]Host, len(source))
for k, v := range source {
result[strings.ToLower(k)] = v
}
return result
}
// Regex description of domain(:port)? pattern to enforce blocks by.
// Global var to avoid compilation penalty at runtime.
// Based on regex from https://stackoverflow.com/a/106223/5427244
//
//nolint:lll
var 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})?$`)
func isValidHostPattern(s string) error {
if len(validHostPattern.FindString(s)) != len(s) {
return fmt.Errorf("invalid host pattern '%s'", s)
}
return nil
}
func (t *Hosts) insert(s string) error {
s = strings.ToLower(s) // domains are not case-sensitive
if err := isValidHostPattern(s); err != nil {
return err
}
t.n.insert(s)
return nil
}
// Match returns the host matching s, where the value can be one of:
// - nil (no match)View on GitHub (pinned to 01ffac6f24)
Solutions
- Use forms like example.com, *.example.com or example.com:8080
- Remove invalid characters, schemes (http://) or paths from the host key
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at lib/types/hosts.go:133 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/fa6db27b435067f5.
Report an issue: GitHub.