gofiber/fiber · error
min constraint requires an argument
Error message
min constraint requires an argument
What it means
The min route-parameter constraint enforces that a matched path segment, parsed as an integer, is greater than or equal to a lower bound. It is declared inline as :param<min(n)>. Its Analyze method (part of the public ConstraintAnalyzer interface) requires exactly one argument; with zero arguments it returns this error. As with the other built-ins, fiber's internal newConstraint swallows Analyze errors, so this is observed when Analyze is invoked directly or through a delegating custom-constraint wrapper.
Solutions
- Supply one integer argument: :param<min(5)>.
- If you want a length-based lower bound rather than a numeric one, use :param<minLen(n)>.
- Verify the parens contain a parseable integer (strconv.Atoi is applied at constraint.go:453).
Example fix
// before
app.Get("/n/:id<min>", h)
// after
app.Get("/n/:id<min(1)>", h) Defensive patterns
Strategy: validation
Validate before calling
// Lint route strings so min always carries one integer argument.
var minNoArg = regexp.MustCompile(`:([^<]+)<min\(\s*\)>`)
for _, p := range routePatterns {
if loc := minNoArg.FindStringIndex(p); loc != nil {
log.Fatalf("route %q: min constraint missing argument", p)
}
} Try / catch
typed, err := minConstraint.Analyze(args)
if err != nil {
return fmt.Errorf("route min constraint: %w", err)
} Prevention
- Treat route patterns as code and lint them in CI.
- Differentiate min (numeric) from minLen (string length) by name to avoid confusion.
- Drive a request through App.Test to confirm the constraint behaves.
When it happens
Trigger: Calling Analyze on a min constraint with no arguments, derived from a route pattern such as :id<min()> (empty parens) or :id<min> (no parens). parseConstraintArgs returns the empty slice unchanged and len(args)==0 trips the guard at constraint.go:450.
Common situations: Forgetting the numeric bound in a route template; refactoring a constraint expression and dropping the argument; whitespace-only content inside the parentheses.
Related errors
- betweenLen constraint requires two arguments
- max constraint requires an argument
- range constraint requires two arguments
- regex constraint requires a pattern argument
- Domain pattern cannot be empty
AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11).
Data as JSON: /api/errors/912850d8446d3842.
Report an issue: GitHub.
Appendix: source
Thrown at constraint.go:450
lo, ok := data[0].(int)
if !ok {
return false
}
hi, ok := data[1].(int)
if !ok {
return false
}
length := len(param)
return length >= lo && length <= hi
}
type minConstraintType struct{}
func (minConstraintType) Name() string { return ConstraintMin }
func (minConstraintType) Analyze(args []string) ([]any, error) {
args = parseConstraintArgs(args)
if len(args) == 0 {
return nil, errors.New("min 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 (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 >= limitView on GitHub (pinned to a105acad6c)