gofiber/fiber · error
Domain pattern ' ' contains invalid parameter name ' ' with…
Error message
Domain pattern '%s' contains invalid parameter name '%s' with character '%c'
What it means
A domain-pattern label written as ':param' contains a character outside the allowed set [a-zA-Z0-9_-] (e.g. ':user.id', ':a/b', or a non-ASCII unicode letter). fiber/v3's domainMatcher rejects these at pattern-compile time because the captured value is interpolated into DNS-style matching and only ASCII-safe label characters are permitted. The check deliberately uses explicit ASCII ranges instead of unicode.IsLetter/IsDigit so non-ASCII letters (invalid in DNS names) are rejected.
Solutions
- Restrict each ':param' name to ASCII letters, digits, underscore, and hyphen only; remove '.', '/', '@', spaces, and any non-ASCII character from the param token.
- If you need nested segments, split them into separate labels (e.g. ':user.:example.com' with two params) rather than embedding '.' inside one param name.
- Validate the pattern string with a regexp like ^:[A-Za-z0-9_-]+$ on each param token before passing it to the domain router.
Example fix
// before
app.Use(":user.name.example.com", handler)
// after
app.Use(":user.:name.example.com", handler) Defensive patterns
Strategy: validation
Validate before calling
// validParamToken reports whether a ':name' token is acceptable to the domain matcher.
func validParamToken(name string) bool {
if name == "" {
return false
}
for _, ch := range name {
if !((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9') || ch == '_' || ch == '-') {
return false
}
}
return true
}
// call before app.Use(domainPattern, ...):
for _, lbl := range strings.Split(strings.TrimSuffix(domainPattern, "."), ".") {
if strings.HasPrefix(lbl, ":") && !validParamToken(lbl[1:]) {
return fmt.Errorf("invalid domain param token %q", lbl)
}
} Try / catch
// Panics happen at app-construction time; wrap router setup in a bootstrap func
// so a bad config aborts startup loudly instead of half-initializing the app.
func buildRouter() (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("router setup failed: %v", r)
}
}()
app.Use(":user.example.com", handler)
return nil
} Prevention
- Keep a single helper that constructs and validates domain patterns; never build pattern strings ad hoc.
- Treat '.' as the only legal separator inside a domain pattern; never put '.', '/', '@', or unicode inside a ':param' name.
- Add a unit test that feeds your generated patterns through the real domain matcher to catch bad tokens in CI.
When it happens
Trigger: Calling any domain-based routing API that compiles a domain pattern (e.g. fiber.New().Use(":user.example.com", ...) or app.Domain(...)-style mounting) where any ':param' segment contains characters other than ASCII letters, digits, underscore, or hyphen — for instance ':user.name', ':café', ':a@b', or ':1st'.
Common situations: Copying a path-style ':param.param' or ':param[key]' Express syntax into a domain pattern; using internationalized/unicode label names; pasting a hostname fragment that contains '.', '/', or '@' inside what was meant to be a single parameter token.
Related errors
- Domain pattern cannot be empty
- Domain pattern ' ' contains empty label at position
- Domain pattern ' ' contains empty parameter name at position
- Domain pattern ' ' contains invalid character '%c' in label
- Domain pattern ' ' exceeds RFC 1035 maximum of 253…
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/d59749cec25c9950.
Report an issue: GitHub.
Appendix: source
Thrown at domain.go:102
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 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))
}View on GitHub (pinned to a105acad6c)