{"record":{"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/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L432-L468","documentation":"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.","triggerScenarios":"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.","commonSituations":"Forgetting the numeric bound in a route template; refactoring a constraint expression and dropping the argument; whitespace-only content inside the parentheses.","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)."],"exampleFix":"// before\napp.Get(\"/n/:id<min>\", h)\n// after\napp.Get(\"/n/:id<min(1)>\", h)","handlingStrategy":"validation","validationCode":"// Lint route strings so min always carries one integer argument.\nvar minNoArg = regexp.MustCompile(`:([^<]+)<min\\(\\s*\\)>`)\nfor _, p := range routePatterns {\n    if loc := minNoArg.FindStringIndex(p); loc != nil {\n        log.Fatalf(\"route %q: min constraint missing argument\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"typed, err := minConstraint.Analyze(args)\nif err != nil {\n    return fmt.Errorf(\"route min constraint: %w\", err)\n}","preventionTips":["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."],"tags":["routing","constraint","route-registration","validation"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}