gofiber/fiber · error
maxLen constraint requires an argument
Error message
maxLen constraint requires an argument
What it means
Returned by maxLenConstraintType.Analyze (constraint.go:362-364) when the maxLen constraint is declared without an integer argument. Symmetric with minLen: maxLen needs the maximum acceptable parameter length to enforce, and Analyze signals the route is malformed without it.
Solutions
- Supply an integer maximum: "/:name<maxLen(32)>".
- Use len for an exact length or betweenLen for a range.
- Write a registration test asserting the constraint compiles.
Example fix
// before
app.Get("/:name<maxLen>", handler)
// after
app.Get("/:name<maxLen(32)>", handler) Defensive patterns
Strategy: validation
Validate before calling
func parseMaxLenArg(args []string) (int, error) {
if len(args) == 0 { return 0, errors.New("maxLen constraint requires an argument") }
return strconv.Atoi(args[0])
} Try / catch
// Same registration-time test pattern as other constraints; // see Test_ConstraintAnalyze_MissingArgs.
Prevention
- Always include an integer argument: <maxLen(32)>.
- Use betweenLen if you need a range.
- Registration tests catch missing arguments before deploy.
When it happens
Trigger: Registering app.Get("/:name<maxLen>", ...) instead of "/:name<maxLen(32)>".
Common situations: Same family as the other length constraints — typo, copy/paste from a no-arg constraint like int, or docs that omitted the argument.
Related errors
- len constraint requires an argument
- minLen constraint requires an argument
- datetime constraint requires a layout argument
- parse constraint arg
- betweenLen constraint requires two arguments
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/0720070003093fba.
Report an issue: GitHub.
Appendix: source
Thrown at constraint.go:363
func (minLenConstraintType) Execute(param string, data []any) bool {
if len(data) == 0 {
return false
}
limit, ok := data[0].(int)
if !ok {
return false
}
return len(param) >= limit
}
type maxLenConstraintType struct{}
func (maxLenConstraintType) Name() string { return ConstraintMaxLen }
func (maxLenConstraintType) Analyze(args []string) ([]any, error) {
args = parseConstraintArgs(args)
if len(args) == 0 {
return nil, errors.New("maxLen constraint requires an argument")
}
n, err := strconv.Atoi(args[0])
if err != nil {
return nil, fmt.Errorf("parse constraint arg: %w", err)
}
return []any{n}, nil
}
func (maxLenConstraintType) Execute(param string, data []any) bool {
if len(data) == 0 {
return false
}
limit, ok := data[0].(int)
if !ok {
return false
}
return len(param) <= limit
}View on GitHub (pinned to a105acad6c)