gofiber/fiber · error

minLen constraint requires an argument

Error message

minLen constraint requires an argument

What it means

Returned by minLenConstraintType.Analyze (constraint.go:336-338) when the minLen constraint is declared without an integer argument. The argument sets the minimum acceptable length of the path parameter; without it the constraint is unusable, so Analyze refuses to compile typed data.

Solutions

  1. Supply an integer length: "/:name<minLen(3)>".
  2. If you want an upper bound instead, use maxLen; for an exact length use len.
  3. Add a registration-time test that fails if a constrained route cannot analyze its arguments.

Example fix

// before
app.Get("/:name<minLen>", handler)

// after
app.Get("/:name<minLen(3)>", handler)
Defensive patterns

Strategy: validation

Validate before calling

func parseMinLenArg(args []string) (int, error) {
    if len(args) == 0 { return 0, errors.New("minLen constraint requires an argument") }
    return strconv.Atoi(args[0])
}

Try / catch

// Constraints are validated at registration; surface failures via a startup test.
// See Test_ConstraintAnalyze_MissingArgs in constraint_test.go for the pattern.

Prevention

When it happens

Trigger: Registering app.Get("/:name<minLen>", ...) — the constraint needs a length, e.g. "/:name<minLen(3)>". Omitting the argument means there is no threshold to enforce.

Common situations: Typos in the constraint syntax; documentation that omits the argument; refactoring from betweenLen (which takes two) to minLen and forgetting to keep one.

Related errors


AI-assisted analysis of gofiber/fiber@a105acad6c (2026-08-11). Data as JSON: /api/errors/8e680925e719532c. Report an issue: GitHub.

Appendix: source

Thrown at constraint.go:337

func (datetimeConstraintType) Execute(param string, data []any) bool {
	if len(data) == 0 {
		return false
	}
	layout, ok := data[0].(string)
	if !ok || layout == "" {
		return false
	}
	_, err := time.Parse(layout, param)
	return err == nil
}

type minLenConstraintType struct{}

func (minLenConstraintType) Name() string { return ConstraintMinLen }
func (minLenConstraintType) Analyze(args []string) ([]any, error) {
	args = parseConstraintArgs(args)
	if len(args) == 0 {
		return nil, errors.New("minLen 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 (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
}

View on GitHub (pinned to a105acad6c)