{"record":{"id":"0720070003093fba","repo":"gofiber/fiber","slug":"maxlen-constraint-requires-an-argument","errorCode":null,"errorMessage":"maxLen constraint requires an argument","messagePattern":"maxLen constraint requires an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":363,"sourceCode":"\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}\n\ntype maxLenConstraintType struct{}\n\nfunc (maxLenConstraintType) Name() string { return ConstraintMaxLen }\nfunc (maxLenConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"maxLen 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 (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}","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L345-L381","documentation":"Returned by maxLenConstraintType.Analyze (constraint.go:362-364) when the maxLen constraint is declared without an integer argument. Symmetric with minLen: maxLen needs the maximum acceptable parameter length to enforce, and Analyze signals the route is malformed without it.","triggerScenarios":"Registering app.Get(\"/:name<maxLen>\", ...) instead of \"/:name<maxLen(32)>\".","commonSituations":"Same family as the other length constraints — typo, copy/paste from a no-arg constraint like int, or docs that omitted the argument.","solutions":["Supply an integer maximum: \"/:name<maxLen(32)>\".","Use len for an exact length or betweenLen for a range.","Write a registration test asserting the constraint compiles."],"exampleFix":"// before\napp.Get(\"/:name<maxLen>\", handler)\n\n// after\napp.Get(\"/:name<maxLen(32)>\", handler)","handlingStrategy":"validation","validationCode":"func parseMaxLenArg(args []string) (int, error) {\n    if len(args) == 0 { return 0, errors.New(\"maxLen constraint requires an argument\") }\n    return strconv.Atoi(args[0])\n}","typeGuard":null,"tryCatchPattern":"// Same registration-time test pattern as other constraints;\n// see Test_ConstraintAnalyze_MissingArgs.","preventionTips":["Always include an integer argument: <maxLen(32)>.","Use betweenLen if you need a range.","Registration tests catch missing arguments before deploy."],"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"}