{"record":{"id":"1c005ef6a063aced","repo":"gofiber/fiber","slug":"max-constraint-requires-an-argument","errorCode":null,"errorMessage":"max constraint requires an argument","messagePattern":"max constraint requires an argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":477,"sourceCode":"func (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\n}\n\ntype maxConstraintType struct{}\n\nfunc (maxConstraintType) Name() string { return ConstraintMax }\nfunc (maxConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"max 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 (maxConstraintType) 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":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L459-L495","documentation":"The max route-parameter constraint enforces that a matched path segment, parsed as an integer, is less than or equal to an upper bound. It is declared inline as :param<max(n)>. Its Analyze method requires exactly one argument; with zero arguments it returns this error. As with sibling constraints, fiber's internal newConstraint silently swallows the Analyze error, so this surfaces only when Analyze is called directly or via a delegating custom constraint.","triggerScenarios":"Calling Analyze on a max constraint with no arguments, derived from a route pattern such as :id<max()> or :id<max>. parseConstraintArgs returns the empty slice and len(args)==0 trips the guard at constraint.go:477.","commonSituations":"Omitting the bound when authoring a route; mixing up max (numeric) with maxLen (string-length); copy-paste error from another constraint.","solutions":["Supply one integer argument: :param<max(100)>.","For a string-length upper bound, use :param<maxLen(n)> instead.","Confirm the argument parses as an integer (constraint.go:480)."],"exampleFix":"// before\napp.Get(\"/n/:id<max>\", h)\n// after\napp.Get(\"/n/:id<max(100)>\", h)","handlingStrategy":"validation","validationCode":"var maxNoArg = regexp.MustCompile(`:([^<]+)<max\\(\\s*\\)>`)\nfor _, p := range routePatterns {\n    if loc := maxNoArg.FindStringIndex(p); loc != nil {\n        log.Fatalf(\"route %q: max constraint missing argument\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"typed, err := maxConstraint.Analyze(args)\nif err != nil {\n    return fmt.Errorf(\"route max constraint: %w\", err)\n}","preventionTips":["Lint route strings so max carries one integer argument.","Distinguish max (numeric) from maxLen (string length).","Add a request-driven test per constrained route."],"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"}