{"record":{"id":"57621590492a80e5","repo":"gofiber/fiber","slug":"fiber-config-regexhandler-must-have-signature-fun","errorCode":null,"errorMessage":"fiber: Config.RegexHandler must have signature func(string) T","messagePattern":"fiber: Config\\.RegexHandler must have signature func\\(string\\) T","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"constraint.go","lineNumber":61,"sourceCode":"\t\tpanic(\"fiber: Config.RegexHandler return type must support MatchString(string) bool\")\n\t}\n\tif isNilRegexMatcher(matcher) {\n\t\tpanic(\"fiber: Config.RegexHandler must not return nil\")\n\t}\n\treturn matcher\n}\n\nfunc validateRegexHandler(handler any) any {\n\tif handler == nil {\n\t\treturn regexp.MustCompile\n\t}\n\thandlerValue := reflect.ValueOf(handler)\n\thandlerType := handlerValue.Type()\n\tif handlerType.Kind() != reflect.Func || handlerValue.IsNil() {\n\t\tpanic(\"fiber: Config.RegexHandler must be a non-nil function\")\n\t}\n\tif handlerType.NumIn() != 1 || handlerType.In(0) != stringType || handlerType.NumOut() != 1 {\n\t\tpanic(\"fiber: Config.RegexHandler must have signature func(string) T\")\n\t}\n\tif !handlerType.Out(0).Implements(regexMatcherType) {\n\t\tpanic(\"fiber: Config.RegexHandler return type must support MatchString(string) bool\")\n\t}\n\treturn handler\n}\n\n// ConstraintHandler is the interface that all constraints must implement.\n// Built-in and custom constraints are treated uniformly through this interface.\ntype ConstraintHandler interface {\n\t// Name returns the constraint identifier used in route patterns (e.g. \"int\", \"minLen\", \"regex\").\n\tName() string\n\n\t// Execute validates a request parameter value against the constraint.\n\t// param is the request parameter value to check.\n\t// data contains the pre-typed constraint data produced by Analyze() at registration time.\n\tExecute(param string, data []any) bool\n}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/constraint.go#L43-L79","documentation":"validateRegexHandler requires the handler to have exactly one input of type string and one output. Any other arity or input type triggers this panic at app init. The expected shape is func(string) T where T implements regexMatcher.","triggerScenarios":"Config.RegexHandler is func(pattern string, flags string) *regexp.Regexp (two inputs), func() *regexp.Regexp (zero inputs), func(string) (*regexp.Regexp, error) (two outputs), or func(int) *regexp.Regexp (wrong input type).","commonSituations":"Wrapping regexp.MustCompile with extra config args; returning (matcher, error) for compile errors; refactor that added parameters.","solutions":["Make the handler exactly func(string) <T> with one input (string) and one output.","Close over any extra configuration rather than adding parameters.","Handle compile errors inside the function (return a sentinel matcher) rather than via a second return value."],"exampleFix":"// before\nRegexHandler: func(p string, flags string) (*regexp.Regexp, error) { ... }\n\n// after\nflags := \"(?i)\"\nRegexHandler: func(p string) *regexp.Regexp {\n  return regexp.MustCompile(flags + p)\n}","handlingStrategy":"validation","validationCode":"// Assert the handler signature is func(string) T\nfunc assertRegexHandlerSig(h any) error {\n    ht := reflect.ValueOf(h).Type()\n    if ht.NumIn() != 1 || ht.In(0).Kind() != reflect.String {\n        return errors.New(\"need exactly one string input\")\n    }\n    if ht.NumOut() != 1 { return errors.New(\"need exactly one output\") }\n    return nil\n}","typeGuard":"func isStringInOneOut(h any) bool {\n    ht := reflect.ValueOf(h).Type()\n    return ht.NumIn() == 1 && ht.In(0).Kind() == reflect.String && ht.NumOut() == 1\n}","tryCatchPattern":null,"preventionTips":["Close over extra configuration instead of adding parameters.","Return a sentinel matcher on compile error rather than (T, error).","Document the expected signature in your config helper."],"tags":["config","regex","reflection","signature","startup"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}