gofiber/fiber · error
Domain pattern '%s' contains empty label at position %d
Error message
Domain pattern '%s' contains empty label at position %d
What it means
Panics from domain.go:88 when a dot-separated label is empty, i.e. consecutive dots in the pattern ("example..com"). Empty labels are invalid per RFC 1035 and would produce ambiguous matching, so parseDomainPattern rejects them per-label.
Source
Thrown at domain.go:88
}
parts := strings.Split(pattern, ".")
// Prevent DoS from patterns with excessive label counts
if len(parts) > maxDomainParts {
panic(fmt.Sprintf("Domain pattern '%s' has %d parts, which exceeds the maximum of %d",
pattern, len(parts), maxDomainParts))
}
m := domainMatcher{
parts: make([]string, len(parts)),
numParts: len(parts),
}
for i, part := range parts {
// Validate no empty labels (e.g., "example..com" is invalid)
if part == "" {
panic(fmt.Sprintf("Domain pattern '%s' contains empty label at position %d", pattern, i))
}
if part[0] == ':' {
// Validate parameter name is not empty
if len(part) == 1 {
panic(fmt.Sprintf("Domain pattern '%s' contains empty parameter name at position %d", pattern, i))
}
paramName := part[1:]
// Validate parameter name contains only ASCII-safe characters (a-z, A-Z, 0-9, underscore, hyphen).
// Using explicit ASCII ranges rather than unicode.IsLetter/IsDigit to reject non-ASCII
// characters that are invalid in DNS names.
for _, ch := range paramName {
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 caseView on GitHub (pinned to 9a4c7e57fe)
Solutions
- Fix the pattern to have no empty labels: "example.com", "sub.example.com".
- Sanitize the pattern by collapsing/stripping stray dots before calling Domain().
- Build patterns from a slice of non-empty labels joined by ".".
Example fix
// before
domain := tenant + "." + suffix // suffix == "" -> "acme."
app.Domain(domain).Get("/", h)
// after
labels := []string{tenant}
if suffix != "" {
labels = append(labels, suffix)
}
domain := strings.Join(labels, ".") // "acme"
app.Domain(domain).Get("/", h) Defensive patterns
Strategy: validation
Validate before calling
for _, label := range strings.Split(pattern, ".") {
if label == "" {
return fmt.Errorf("domain pattern has empty label")
}
}
app.Domain(pattern).Get("/", h) Prevention
- Build patterns by joining a slice of non-empty labels with ".".
- Sanitize stray leading/trailing/double dots before registering.
- Unit-test pattern construction with empty inputs.
When it happens
Trigger: app.Domain("example..com"), app.Domain(".example.com") (leading dot yields empty first label after split), or app.Domain("example.com.") is fine (trailing dot trimmed), but "example..com." is not.
Common situations: Concatenating labels with a missing value: domain := part + "." + part2 where part2 is empty; trailing/leading dots from sloppy string formatting; config typos.
Related errors
- Domain pattern '%s' exceeds RFC 1035 maximum of 253 characte
- Domain pattern '%s' has label '%s' exceeding RFC 1035 limit
- Domain pattern '%s' contains invalid character '%c' in label
- Domain pattern cannot be empty
- Domain pattern '%s' has %d parts, which exceeds the maximum
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/6b4f3f00249a5121.json.
Report an issue: GitHub.