{"id":"6c3ce85f5fe0815e","repo":"gofiber/fiber","slug":"parse-constraint-arg-w","errorCode":null,"errorMessage":"parse constraint arg: %w","messagePattern":"parse constraint arg: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"constraint.go","lineNumber":341,"sourceCode":"\tlayout, ok := data[0].(string)\n\tif !ok || layout == \"\" {\n\t\treturn false\n\t}\n\t_, err := time.Parse(layout, param)\n\treturn err == nil\n}\n\ntype minLenConstraintType struct{}\n\nfunc (minLenConstraintType) Name() string { return ConstraintMinLen }\nfunc (minLenConstraintType) Analyze(args []string) ([]any, error) {\n\targs = parseConstraintArgs(args)\n\tif len(args) == 0 {\n\t\treturn nil, errors.New(\"minLen 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 (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 }","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/constraint.go#L323-L359","documentation":"Returned by minLenConstraintType.Analyze (constraint.go:341) when strconv.Atoi cannot parse the first constraint argument. Fiber route constraints like :param<minLen(N)> are analyzed at route registration; minLen expects an integer length, so a non-numeric argument fails parsing and is surfaced with this wrap.","triggerScenarios":"Registering a route whose minLen constraint argument is not an integer, e.g. app.Get(\"/:name<minLen(abc)>\", ...). The Analyze phase runs at app.Register/AddRoute time, so the error appears during routing setup, not request handling. Multiple comma-separated args that are non-integer also hit it.","commonSituations":"Typo in the constraint (minLen(three)); templating/code-gen that substitutes a variable without quotes; copy-paste from a maxLen/range route leaving a non-numeric value; a dynamically-built route pattern concatenating user input that is not validated as an integer.","solutions":["Provide an integer literal to minLen, e.g. /:name<minLen(3)>.","When building route patterns dynamically, strconv.Itoa the integer before concatenation.","Validate any external input feeding a constraint argument is numeric before registering the route."],"exampleFix":"// before — non-integer minLen argument\napp.Get(\"/:name<minLen(minSize)>\", handler)\n\n// after — integer argument\napp.Get(\"/:name<minLen(3)>\", handler)\n// or, dynamically:\napp.Get(\"/:name<minLen(\"+strconv.Itoa(minSize)+\")>\", handler)","handlingStrategy":"validation","validationCode":"// Validate route constraint args are integers before registration.\nvar intArg = regexp.MustCompile(`^\\d+$`)\nfunc validMinLenArg(arg string) bool { return intArg.MatchString(arg) }","typeGuard":"func isIntArg(s string) bool { _, err := strconv.Atoi(s); return err == nil }","tryCatchPattern":null,"preventionTips":["Always pass integer literals to minLen, e.g. /:name<minLen(3)>.","Use strconv.Itoa when building route patterns from variables.","Validate external/config input feeding constraint arguments at load time."],"tags":["routing","constraint","minlen","registration"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}