{"id":"f952caa538547eda","repo":"go-redis/redis","slug":"handler-cannot-be-nil","errorCode":null,"errorMessage":"handler cannot be nil","messagePattern":"handler cannot be nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"push/errors.go","lineNumber":48,"sourceCode":"\tProcessorTypeCustom        = ProcessorType(\"custom\")\n)\n\n// ProcessorOperation represents the operation being performed by the processor\n// defined as a custom type for better readability and easier maintenance\ntype ProcessorOperation string\n\nconst (\n\t// ProcessorOperations\n\tProcessorOperationProcess    = ProcessorOperation(\"process\")\n\tProcessorOperationRegister   = ProcessorOperation(\"register\")\n\tProcessorOperationUnregister = ProcessorOperation(\"unregister\")\n\tProcessorOperationUnknown    = ProcessorOperation(\"unknown\")\n)\n\n// Common error variables for reuse\nvar (\n\t// ErrHandlerNil is returned when attempting to register a nil handler\n\tErrHandlerNil = errors.New(ReasonHandlerNil)\n)\n\n// Registry errors\n\n// ErrHandlerExists creates an error for when attempting to overwrite an existing handler\nfunc ErrHandlerExists(pushNotificationName string) error {\n\treturn NewHandlerError(ProcessorOperationRegister, pushNotificationName, ReasonHandlerExists, nil)\n}\n\n// ErrProtectedHandler creates an error for when attempting to unregister a protected handler\nfunc ErrProtectedHandler(pushNotificationName string) error {\n\treturn NewHandlerError(ProcessorOperationUnregister, pushNotificationName, ReasonHandlerProtected, nil)\n}\n\n// VoidProcessor errors\n\n// ErrVoidProcessorRegister creates an error for when attempting to register a handler on void processor\nfunc ErrVoidProcessorRegister(pushNotificationName string) error {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/push/errors.go#L30-L66","documentation":"push.ErrHandlerNil is returned when a caller registers a nil handler with a push notification processor (the Registry). The push package dispatches RESP3 push notifications (e.g. maintenance MOVING/MIGRATING signals) to registered handlers; a nil handler would panic on dispatch, so registration is rejected. It is a sentinel error checkable via push.IsHandlerNilError / errors.Is.","triggerScenarios":"Calling Register on a push processor/registry with a nil handler function. Passing an uninitialized handler variable. Conditionally building a handler that ends up nil due to a missed branch.","commonSituations":"Custom RESP3 push-notification integrations. Maintenance-notifications subsystem extensions that register handlers programmatically. Test code that stubs out handlers with nil.","solutions":["Ensure the handler passed to Register is non-nil before calling it.","Check the handler variable for nil with an explicit guard before registration.","If the handler is optional, skip registration entirely rather than passing nil."],"exampleFix":"// before\nregistry.Register(\"MOVING\", nil)\n\n// after\nif handler == nil {\n    return errors.New(\"handler must not be nil\")\n}\nregistry.Register(\"MOVING\", handler)","handlingStrategy":"validation","validationCode":"func safeRegister(r *push.Registry, name string, h push.Handler) error {\n    if h == nil {\n        return push.ErrHandlerNil\n    }\n    return r.Register(name, h)\n}","typeGuard":"func isNilHandler(h push.Handler) bool {\n    return h == nil // Handler is an interface; a nil interface compares to nil\n}","tryCatchPattern":"if err := registry.Register(name, handler); err != nil {\n    if push.IsHandlerNilError(err) {\n        // handler was nil; initialize it before retrying\n    }\n}","preventionTips":["Always nil-check handler variables before registering them.","If a handler is optional, skip registration rather than passing nil.","Initialize handlers at construction time to avoid nil from missed branches."],"tags":["push","resp3","validation","nil-guard","handler"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}