{"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/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/constraint.go#L459-L495","documentation":"Thrown by maxConstraintType.Analyze (constraint.go:477) when the 'max' route-parameter constraint is registered without its required numeric argument. 'max(N)' enforces that the integer parameter is less-than-or-equal to N; without N there is no upper bound, so Analyze refuses to compile the constraint. As with all built-in constraint Analyze failures, route registration discards the error (newConstraint only stores typedData on success), meaning the route will compile but never match a request.","triggerScenarios":"A route pattern such as app.Get(\"/:qty<max>\", ...) missing the (N) bound, or calling maxConstraintType{}.Analyze([]string{}) directly. Custom constraints that delegate to max with an empty args slice also surface it.","commonSituations":"Mistakenly assuming 'max' works like 'int' (argument-free), or refactoring a route and dropping the number. Pattern strings built from configuration where the upper bound is missing are a common culprit.","solutions":["Provide the upper bound, e.g. /:qty<max(100)> instead of /:qty<max>.","Validate generated route patterns contain an argument for argument-required constraints before registering.","Write a registration-time smoke test that hits the route to catch the silent no-match early."],"exampleFix":"// before\napp.Get(\"/:qty<max>\", handler)\n\n// after\napp.Get(\"/:qty<max(100)>\", handler)","handlingStrategy":"validation","validationCode":"// Reject 'max' without an argument before app.Listen.\nfunc checkMaxConstraint(pattern string) error {\n    if regexp.MustCompile(`<max\\s*>`).MatchString(pattern) {\n        return errors.New(\"max constraint requires (N) argument\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember 'int' is argument-free but 'min'/'max' are not.","Validate generated route strings in CI before deployment.","Keep a single source of truth for route patterns to avoid drift."],"tags":["routing","constraint","config","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}