{"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/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/constraint.go#L486-L522","documentation":"Thrown by rangeConstraintType.Analyze (constraint.go:504) when the 'range' constraint is given fewer than two arguments. 'range(lo,hi)' validates that the integer parameter falls within an inclusive [lo,hi] interval, so Analyze needs both bounds (parsed with strconv.Atoi). A pattern like /:n<range> or /:n<range(5)> has an incomplete interval and cannot enforce a bounded check.","triggerScenarios":"Route patterns /:n<range>, /:n<range(5)>, or any range constraint where parseConstraintArgs yields fewer than two elements. Direct call rangeConstraintType{}.Analyze([]string{\"1\"}) returns it as well.","commonSituations":"Forgetting the second bound, using a wrong separator (the data separator is ','), or hand-constructing the args slice. Confusion between 'range' (numeric interval) and 'betweenLen' (length interval) also leads to wrong argument counts.","solutions":["Supply both bounds as a comma-separated pair, e.g. /:n<range(1,100)>.","Confirm you used the comma separator and not a semicolon (semicolons separate distinct constraints, not range bounds).","If generating patterns programmatically, assert len(args) >= 2 before emitting a range constraint."],"exampleFix":"// before\napp.Get(\"/:page<range(1)>\", handler)\n\n// after\napp.Get(\"/:page<range(1,50)>\", handler)","handlingStrategy":"validation","validationCode":"// Ensure 'range' constraints carry two comma-separated bounds.\nfunc checkRangeConstraint(pattern string) error {\n    ranges := regexp.MustCompile(`<range\\(([^)]*)\\)>`).FindAllStringSubmatch(pattern, -1)\n    for _, m := range ranges {\n        parts := strings.Split(m[1], \",\")\n        if len(parts) < 2 {\n            return fmt.Errorf(\"range(%s) needs two arguments\", m[1])\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the comma separator for range bounds; semicolons separate distinct constraints.","Distinguish 'range' (numeric) from 'betweenLen' (length) to avoid argument-count confusion.","Assert bound counts in a route-validation helper run at startup."],"tags":["routing","constraint","config","fiber"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}