{"id":"912850d8446d3842","repo":"gofiber/fiber","slug":"min-constraint-requires-an-argument","errorCode":null,"errorMessage":"min constraint requires an argument","messagePattern":"min constraint requires an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":450,"sourceCode":"\tlo, ok := data[0].(int)\n\tif !ok {\n\t\treturn false\n\t}\n\thi, ok := data[1].(int)\n\tif !ok {\n\t\treturn false\n\t}\n\tlength := len(param)\n\treturn length >= lo && length <= hi\n}\n\ntype minConstraintType struct{}\n\nfunc (minConstraintType) Name() string { return ConstraintMin }\nfunc (minConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"min constraint requires an argument\")\n\t}\n\tn, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse constraint arg: %w\", err)\n\t}\n\treturn []any{n}, nil\n}\n\nfunc (minConstraintType) Execute(param string, data []any) bool {\n\tif len(data) == 0 {\n\t\treturn false\n\t}\n\tlimit, ok := data[0].(int)\n\tif !ok {\n\t\treturn false\n\t}\n\tnum, err := strconv.Atoi(param)\n\treturn err == nil && num >= limit","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/constraint.go#L432-L468","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add the numeric argument in the route pattern, e.g. change /:age<min> to /:age<min(18)>.","If building the pattern dynamically, assert the argument slice is non-empty before emitting the min constraint.","Add a startup test that exercises each constrained route so a misconfigured constraint fails fast instead of silently never matching."],"exampleFix":"// before\napp.Get(\"/:age<min>\", handler)\n\n// after\napp.Get(\"/:age<min(18)>\", handler)","handlingStrategy":"validation","validationCode":"// Validate route patterns at startup before registering them.\nfunc requireArgConstraints(pattern string) error {\n    // min/max/len need one arg, range/betweenLen need two, regex needs a pattern.\n    re := regexp.MustCompile(`<(min|max|len|range|betweenLen|regex)\\s*>`)\n    if loc := re.FindString(pattern); loc != \"\" {\n        return fmt.Errorf(\"constraint %s missing required argument\", loc)\n    }\n    return nil\n}\n\nfor _, r := range routes {\n    if err := requireArgConstraints(r); err != nil {\n        log.Fatal(err)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply the (N) argument for min/max/len constraints and (lo,hi) for range/betweenLen.","Add a registration-time integration test that issues a request against every constrained route so a silent no-match fails the build.","Centralize constraint syntax in constants or helper builders rather than hand-typing patterns."],"tags":["routing","constraint","config","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}