gofiber/fiber · error
max constraint requires an argument
Error message
max constraint requires an argument
What it means
Thrown by maxConstraintType.Analyze (constraint.go:477) when the 'max' route-parameter constraint is registered without its required numeric argument. 'max(N)' enforces that the integer parameter is less-than-or-equal to N; without N there is no upper bound, so Analyze refuses to compile the constraint. As with all built-in constraint Analyze failures, route registration discards the error (newConstraint only stores typedData on success), meaning the route will compile but never match a request.
Source
Thrown at constraint.go:477
func (minConstraintType) Execute(param string, data []any) bool {
if len(data) == 0 {
return false
}
limit, ok := data[0].(int)
if !ok {
return false
}
num, err := strconv.Atoi(param)
return err == nil && num >= limit
}
type maxConstraintType struct{}
func (maxConstraintType) Name() string { return ConstraintMax }
func (maxConstraintType) Analyze(args []string) ([]any, error) {
args = parseConstraintArgs(args)
if len(args) == 0 {
return nil, errors.New("max 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 (maxConstraintType) Execute(param string, data []any) bool {
if len(data) == 0 {
return false
}
limit, ok := data[0].(int)
if !ok {
return false
}
num, err := strconv.Atoi(param)
return err == nil && num <= limitView on GitHub (pinned to 9a4c7e57fe)
Solutions
- Provide the upper bound, e.g. /:qty<max(100)> instead of /:qty<max>.
- Validate generated route patterns contain an argument for argument-required constraints before registering.
- Write a registration-time smoke test that hits the route to catch the silent no-match early.
Example fix
// before
app.Get("/:qty<max>", handler)
// after
app.Get("/:qty<max(100)>", handler) Defensive patterns
Strategy: validation
Validate before calling
// Reject 'max' without an argument before app.Listen.
func checkMaxConstraint(pattern string) error {
if regexp.MustCompile(`<max\s*>`).MatchString(pattern) {
return errors.New("max constraint requires (N) argument")
}
return nil
} Prevention
- Remember 'int' is argument-free but 'min'/'max' are not.
- Validate generated route strings in CI before deployment.
- Keep a single source of truth for route patterns to avoid drift.
When it happens
Trigger: A route pattern such as app.Get("/:qty<max>", ...) missing the (N) bound, or calling maxConstraintType{}.Analyze([]string{}) directly. Custom constraints that delegate to max with an empty args slice also surface it.
Common situations: Mistakenly assuming 'max' works like 'int' (argument-free), or refactoring a route and dropping the number. Pattern strings built from configuration where the upper bound is missing are a common culprit.
Related errors
- min constraint requires an argument
- range constraint requires two arguments
- regex constraint requires a pattern argument
- fiber: Config.RegexHandler return type must support MatchStr
- fiber: Config.RegexHandler must not return nil
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/1c005ef6a063aced.json.
Report an issue: GitHub.