{"record":{"id":"7a9c339884dcdd58","repo":"gofiber/fiber","slug":"len-constraint-requires-an-argument","errorCode":null,"errorMessage":"len constraint requires an argument","messagePattern":"len constraint requires an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":389,"sourceCode":"\nfunc (maxLenConstraintType) 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}\n\ntype lenConstraintType struct{}\n\nfunc (lenConstraintType) Name() string { return ConstraintLen }\nfunc (lenConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"len 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 (lenConstraintType) 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":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L371-L407","documentation":"Returned by lenConstraintType.Analyze (constraint.go:388-390) when the len constraint is declared without an integer argument. The len constraint enforces an exact parameter length, so the target length is mandatory; Analyze rejects the route declaration otherwise.","triggerScenarios":"Registering app.Get(\"/:code<len>\", ...) instead of \"/:code<len(5)>\".","commonSituations":"Confusing len with betweenLen (which takes two args); typo; documentation that omitted the argument; refactor that dropped the argument.","solutions":["Supply the exact integer length: \"/:code<len(5)>\".","If a range is needed, switch to betweenLen(min,max).","Add a registration-time test for each constrained route."],"exampleFix":"// before\napp.Get(\"/:code<len>\", handler)\n\n// after\napp.Get(\"/:code<len(5)>\", handler)","handlingStrategy":"validation","validationCode":"func parseLenArg(args []string) (int, error) {\n    if len(args) == 0 { return 0, errors.New(\"len constraint requires an argument\") }\n    return strconv.Atoi(args[0])\n}","typeGuard":null,"tryCatchPattern":"// Same registration-time test pattern as minLen/maxLen;\n// see Test_ConstraintAnalyze_MissingArgs.","preventionTips":["Always include an integer length: <len(5)>.","Switch to betweenLen for ranges.","Registration tests are the safety net for missing constraint arguments."],"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"}