{"record":{"id":"8e680925e719532c","repo":"gofiber/fiber","slug":"minlen-constraint-requires-an-argument","errorCode":null,"errorMessage":"minLen constraint requires an argument","messagePattern":"minLen constraint requires an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":337,"sourceCode":"func (datetimeConstraintType) Execute(param string, data []any) bool {\n\tif len(data) == 0 {\n\t\treturn false\n\t}\n\tlayout, ok := data[0].(string)\n\tif !ok || layout == \"\" {\n\t\treturn false\n\t}\n\t_, err := time.Parse(layout, param)\n\treturn err == nil\n}\n\ntype minLenConstraintType struct{}\n\nfunc (minLenConstraintType) Name() string { return ConstraintMinLen }\nfunc (minLenConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"minLen 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 (minLenConstraintType) 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\treturn len(param) >= limit\n}","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L319-L355","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in the constraint syntax; documentation that omits the argument; refactoring from betweenLen (which takes two) to minLen and forgetting to keep one.","solutions":["Supply an integer length: \"/:name<minLen(3)>\".","If you want an upper bound instead, use maxLen; for an exact length use len.","Add a registration-time test that fails if a constrained route cannot analyze its arguments."],"exampleFix":"// before\napp.Get(\"/:name<minLen>\", handler)\n\n// after\napp.Get(\"/:name<minLen(3)>\", handler)","handlingStrategy":"validation","validationCode":"func parseMinLenArg(args []string) (int, error) {\n    if len(args) == 0 { return 0, errors.New(\"minLen constraint requires an argument\") }\n    return strconv.Atoi(args[0])\n}","typeGuard":null,"tryCatchPattern":"// Constraints are validated at registration; surface failures via a startup test.\n// See Test_ConstraintAnalyze_MissingArgs in constraint_test.go for the pattern.","preventionTips":["Always include an integer argument: <minLen(3)>.","Add a registration-time test exercising each constrained route.","Review constraint arguments during code review."],"tags":["routing","constraints","validation","fiber"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}