{"record":{"id":"6c3ce85f5fe0815e","repo":"gofiber/fiber","slug":"parse-constraint-arg-w","errorCode":null,"errorMessage":"parse constraint arg: %w","messagePattern":"parse constraint arg: %w","errorType":"validation","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/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L323-L359","documentation":"Thrown by the minLen route-parameter constraint's Analyze step at route-registration time. minLen expects one base-10 integer argument (the minimum character length of the param); strconv.Atoi rejects anything that is not a clean integer, and the error is wrapped as 'parse constraint arg: <Atoi error>'. Note: Fiber's built-in constraint registration swallows Analyze errors (see findConstraintHandler, constraint.go:188), so the user-visible symptom is a dead route whose constraint never matches, not a panic.","triggerScenarios":"Registering a route whose minLen argument is non-integer, e.g. app.Get(\"/:name<minLen(three)>)\", or \"/:name<minLen(3.5)>\", or \"/:name<minLen(3px)>\". Calling minLenConstraintType{}.Analyze([]string{\"abc\"}) directly (as the test suite does) returns this error explicitly.","commonSituations":"Typing the limit as a word instead of a digit, pasting a float or a value with units, leaving a placeholder from copied docs, or a tool generating route patterns with templated non-numeric values.","solutions":["Change the minLen argument to an integer literal, e.g. \"/:name<minLen(3)>\".","If the value is templated/computed, format it with %d or strconv.Itoa so only digits reach the pattern.","Write a unit test that calls Analyze on the constraint args to catch malformed limits at build time.","If the route seems to silently match nothing, suspect this: the swallowed Analyze error leaves typedData nil, Execute's data[0].(int) fails, and every request is rejected."],"exampleFix":"// before\napp.Get(\"/:name<minLen(three)>\", handler)\n\n// after\napp.Get(\"/:name<minLen(3)>\", handler)","handlingStrategy":"validation","validationCode":"// validate a minLen argument is a clean integer before registering the route\nfunc validIntArg(arg string) bool {\n    _, err := strconv.Atoi(arg)\n    return err == nil\n}\n\n// at startup, scan your route table's constraint args\nfor _, a := range minLenArgs {\n    if !validIntArg(a) {\n        log.Fatalf(\"minLen arg %q is not an integer\", a)\n    }\n}","typeGuard":"null","tryCatchPattern":"// Analyze is the public seam; assert it succeeds in a test\n_, err := minLenConstraintType{}.Analyze([]string{arg})\nif err != nil {\n    t.Fatalf(\"minLen arg %q: %v\", arg, err)\n}","preventionTips":["Always write constraint arguments as integer literals in route patterns.","When generating routes from config, render bounds with strconv.Itoa, never %s or %v.","Add a unit test that calls Analyze for every constraint argument in the route table at build time.","Remember a bad arg is silently swallowed at registration: a route that matches nothing is the tell."],"tags":["routing","validation","configuration","gofiber","constraints"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}