{"record":{"id":"0977b9b97e5991d2","repo":"gofiber/fiber","slug":"range-constraint-requires-two-arguments","errorCode":null,"errorMessage":"range constraint requires two arguments","messagePattern":"range constraint requires two arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":504,"sourceCode":"func (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\n}\n\ntype rangeConstraintType struct{}\n\nfunc (rangeConstraintType) Name() string { return ConstraintRange }\nfunc (rangeConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) < 2 {\n\t\treturn nil, errors.New(\"range constraint requires two arguments\")\n\t}\n\tlo, err := strconv.Atoi(args[0])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse constraint arg: %w\", err)\n\t}\n\thi, err := strconv.Atoi(args[1])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse constraint arg: %w\", err)\n\t}\n\treturn []any{lo, hi}, nil\n}\n\nfunc (rangeConstraintType) Execute(param string, data []any) bool {\n\tif len(data) < 2 {\n\t\treturn false\n\t}\n\tlo, ok := data[0].(int)\n\tif !ok {","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L486-L522","documentation":"The range route-parameter constraint enforces that a matched path segment, parsed as an integer, lies within an inclusive [lo, hi] range. It is declared inline as :param<range(lo,hi)>. Its Analyze method requires two integer arguments; with fewer than two it returns this error. The internal newConstraint call site swallows Analyze errors, so this surfaces only when Analyze is invoked directly or through a delegating custom-constraint wrapper.","triggerScenarios":"Calling Analyze on a range constraint with fewer than two arguments, derived from a route pattern such as :id<range(5)>, :id<range()>, :id<range>, or :id<range(1\\,10)> (escaped comma). parseConstraintArgs splits a single-element slice on the comma; without a comma it stays a one-element slice and len(args)<2 trips the guard at constraint.go:504.","commonSituations":"Forgetting the upper bound; an escaped comma merging two args into one; confusing range (numeric) with betweenLen (string-length).","solutions":["Provide two integer arguments: :param<range(1,100)>.","If a single bound suffices, use :param<min(n)> or :param<max(n)>.","Confirm the comma separator is not escaped (\\, would merge arguments).","For length-based ranges use :param<betweenLen(lo,hi)> instead."],"exampleFix":"// before\napp.Get(\"/n/:id<range(10)>\", h)\n// after\napp.Get(\"/n/:id<range(10,100)>\", h)","handlingStrategy":"validation","validationCode":"var rangeArgs = regexp.MustCompile(`:([^<]+)<range\\(([^)]*)\\)>`)\nfor _, p := range routePatterns {\n    m := rangeArgs.FindStringSubmatch(p)\n    if m != nil && len(strings.Split(m[2], \",\")) != 2 {\n        log.Fatalf(\"route %q: range needs exactly two integer args\", p)\n    }\n}","typeGuard":null,"tryCatchPattern":"typed, err := rangeConstraint.Analyze(args)\nif err != nil {\n    return fmt.Errorf(\"route range constraint: %w\", err)\n}","preventionTips":["Lint that range has exactly two comma-separated integer args.","For length ranges use betweenLen; for one bound use min/max.","Confirm no escaped comma (\\,) is merging the two arguments."],"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"}