gofiber/fiber · error

min constraint requires an argument

Error message

min constraint requires an argument

What it means

Thrown by minConstraintType.Analyze (constraint.go:450) when the route-parameter constraint 'min' is registered without its required numeric argument. The 'min(N)' constraint enforces that the parsed integer parameter is greater-than-or-equal to N, so Analyze needs exactly one integer to compile. With no argument there is no lower bound to validate against, so the constraint cannot be built. Note: at route-registration time newConstraint swallows Analyze errors, so the route silently never matches; the error surfaces when Analyze is invoked directly (e.g. via a custom constraint wrapper or explicit validation).

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 >= limit

View on GitHub (pinned to 9a4c7e57fe)

Solutions

  1. Add the numeric argument in the route pattern, e.g. change /:age<min> to /:age<min(18)>.
  2. If building the pattern dynamically, assert the argument slice is non-empty before emitting the min constraint.
  3. Add a startup test that exercises each constrained route so a misconfigured constraint fails fast instead of silently never matching.

Example fix

// before
app.Get("/:age<min>", handler)

// after
app.Get("/:age<min(18)>", handler)
Defensive patterns

Strategy: validation

Validate before calling

// Validate route patterns at startup before registering them.
func requireArgConstraints(pattern string) error {
    // min/max/len need one arg, range/betweenLen need two, regex needs a pattern.
    re := regexp.MustCompile(`<(min|max|len|range|betweenLen|regex)\s*>`)
    if loc := re.FindString(pattern); loc != "" {
        return fmt.Errorf("constraint %s missing required argument", loc)
    }
    return nil
}

for _, r := range routes {
    if err := requireArgConstraints(r); err != nil {
        log.Fatal(err)
    }
}

Prevention

When it happens

Trigger: Writing a route pattern like app.Get("/:age<min>", ...) where the constraint omits the parenthesized value. Directly calling minConstraintType{}.Analyze([]string{}) or registering a custom constraint whose Analyze delegates to min with an empty arg list also returns it.

Common situations: Developers new to Fiber v3 constraint syntax forget the (N) argument, or template-generate route strings and accidentally drop the argument. Copy-pasting from 'int' (which takes no arg) into 'min' is a frequent cause.

Related errors


AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04). Data as JSON: /data/errors/912850d8446d3842.json. Report an issue: GitHub.