gofiber/fiber · error
Domain pattern '%s' contains invalid character '%c' in label
Error message
Domain pattern '%s' contains invalid character '%c' in label '%s'
What it means
Panics from domain.go:119 when a constant label (after lowercasing per RFC 4343) contains a character other than ASCII a-z, 0-9, or hyphen. These are the only characters legal in DNS hostnames, so any other byte (underscore, wildcard '*', slash, unicode, etc.) is rejected.
Source
Thrown at domain.go:119
if !isASCIIAlphanumeric(ch) && ch != '_' && ch != '-' {
panic(fmt.Sprintf("Domain pattern '%s' contains invalid parameter name '%s' with character '%c'", pattern, paramName, ch))
}
}
m.paramIdx = append(m.paramIdx, i)
m.paramNames = append(m.paramNames, paramName) // preserve original case
m.parts[i] = part // keep ":param" marker for matching
} else {
// Only lowercase constant labels (RFC 4343)
// Enforce RFC 1035 per-label length limit (63 characters)
if len(part) > 63 {
panic(fmt.Sprintf("Domain pattern '%s' has label '%s' exceeding RFC 1035 limit of 63 characters (%d chars)",
pattern, part, len(part)))
}
// Validate label contains only valid ASCII domain characters (a-z, 0-9, hyphen).
normalized := utilsstrings.ToLower(part)
for _, ch := range normalized {
if !isASCIIAlphanumeric(ch) && ch != '-' {
panic(fmt.Sprintf("Domain pattern '%s' contains invalid character '%c' in label '%s'", pattern, ch, part))
}
}
m.parts[i] = normalized
}
}
// Check if the domain pattern has too many parameters
if len(m.paramNames) > maxParams {
panic(fmt.Sprintf("Domain pattern '%s' has %d parameters, which exceeds the maximum of %d",
pattern, len(m.paramNames), maxParams))
}
return m
}
// match checks if a hostname matches the domain pattern.
// It returns true if matched and a slice of parameter values (parallel to paramNames).
// Uses a stack-allocated buffer to avoid heap allocation for typical domain names.View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Use only letters, digits, and hyphens in constant labels.
- Use a parameter label (":sub.example.com") instead of '*' to capture arbitrary subdomains.
- Punycode-encode IDN labels before registering them.
Example fix
// before
app.Domain("*.example.com").Get("/", h) // '*' invalid
// after - capture any single subdomain label
app.Domain(":sub.example.com").Get("/", h)
// then read fiber.DomainParam(c, "sub") Defensive patterns
Strategy: validation
Validate before calling
for _, label := range strings.Split(pattern, ".") {
if strings.HasPrefix(label, ":") {
continue
}
lower := strings.ToLower(label)
for _, ch := range lower {
if !((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '-') {
return fmt.Errorf("invalid char %q in label %s", ch, label)
}
}
}
app.Domain(pattern).Get("/", h) Prevention
- Use only [a-z0-9-] in constant labels.
- Use ':param' labels instead of '*' for wildcard subdomains.
- Punycode-encode IDN labels before registering.
When it happens
Trigger: app.Domain("sub_domain.example.com") panics on '_'; app.Domain("*.example.com") panics on '*'; app.Domain("cafe.example.com") with a non-ASCII 'e' panics. Wildcards are not supported as constant labels.
Common situations: Trying to use wildcard subdomains via '*' (fiber's domain router is pattern-based on labels, not glob); underscores from service-discovery names; pasting internationalized names without IDNA punycode encoding.
Related errors
- Domain pattern '%s' exceeds RFC 1035 maximum of 253 characte
- Domain pattern '%s' contains empty label at position %d
- Domain pattern '%s' contains invalid parameter name '%s' wit
- Domain pattern '%s' has label '%s' exceeding RFC 1035 limit
- Domain pattern cannot be empty
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/a4bbfe77b1664a2e.json.
Report an issue: GitHub.