{"record":{"id":"1c5ed81185ca66f8","repo":"kataras/iris","slug":"at-least-one-context-request-handler-function-is-r","errorCode":null,"errorMessage":"at least one context request handler function is required","messagePattern":"at least one context request handler function is required","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/errors/handlers.go","lineNumber":233,"sourceCode":"//\t\t\tvalidation.Slice(\"hobbies\", r.Hobbies).Length(1, 10),\n//\t\t)\n//\t}\nfunc Validation[T any](validators ...ContextRequestFunc[T]) context.Handler {\n\tif len(validators) == 0 {\n\t\treturn nil\n\t}\n\n\tvalidator := joinContextRequestFuncs(validators)\n\n\treturn func(ctx *context.Context) {\n\t\tctx.Values().Set(contextRequestHandlerFuncKey, validator)\n\t\tctx.Next()\n\t}\n}\n\nfunc joinContextRequestFuncs[T any](requestHandlerFuncs []ContextRequestFunc[T]) ContextRequestFunc[T] {\n\tif len(requestHandlerFuncs) == 0 || requestHandlerFuncs[0] == nil {\n\t\tpanic(\"at least one context request handler function is required\")\n\t}\n\n\tif len(requestHandlerFuncs) == 1 {\n\t\treturn requestHandlerFuncs[0]\n\t}\n\n\treturn func(ctx *context.Context, req T) error {\n\t\tfor _, handler := range requestHandlerFuncs {\n\t\t\tif handler == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif err := handler(ctx, req); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\treturn nil","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/x/errors/handlers.go#L215-L251","documentation":"joinContextRequestFuncs combines a variadic list of ContextRequestFunc handlers; it panics when the list is empty or its first element is nil, because there must be at least one handler to compose and return.","triggerScenarios":"Calling x/errors Validation(...) (which calls joinContextRequestFuncs) with zero handler functions or with handlers[0] == nil.","commonSituations":"Building a validation chain dynamically by appending handlers in a loop that appends nothing; accidentally appending a nil handler from an uninitialized variable.","solutions":["Pass at least one non-nil ContextRequestFunc to Validation","Filter nil handlers before building the chain","Guard the call site: only call Validation when len(handlers) > 0"],"exampleFix":"// before\nh := xerrors.Validation()\n// after\nif len(handlers) > 0 && handlers[0] != nil {\n    h = xerrors.Validation(handlers...)\n}","handlingStrategy":"validation","validationCode":"func canJoinRequestFuncs[T any](fs []ContextRequestFunc[T]) bool {\n    return len(fs) > 0 && fs[0] != nil\n}","typeGuard":null,"tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Printf(\"handler chain panic: %v\", r) } }()\nh := joinContextRequestFuncs(handlers)","preventionTips":["Never append nil handlers to handler slices","Check slice length before composing chains","Use builder helpers that reject nil entries early"],"tags":["go","panic","validation","handlers"],"backgroundTag":"empty-handler-chain","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}