{"record":{"id":"ad25e423d7704f17","repo":"dgraph-io/badger","slug":"errnilcallback","errorCode":"ErrNilCallback","errorMessage":"Callback cannot be nil","messagePattern":"Callback cannot be nil","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":97,"sourceCode":"\tErrZeroBandwidth = stderrors.New(\"Bandwidth must be greater than zero\")\n\n\t// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows\n\tErrWindowsNotSupported = stderrors.New(\"Read-only mode is not supported on Windows\")\n\n\t// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9\n\tErrPlan9NotSupported = stderrors.New(\"Read-only mode is not supported on Plan 9\")\n\n\t// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of\n\t// corrupt data to allow Badger to run properly.\n\tErrTruncateNeeded = stderrors.New(\n\t\t\"Log truncate required to run DB. This might result in data loss\")\n\n\t// ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all\n\t// data from Badger, we stop accepting new writes, by returning this error.\n\tErrBlockedWrites = stderrors.New(\"Writes are blocked, possibly due to DropAll or Close\")\n\n\t// ErrNilCallback is returned when subscriber's callback is nil.\n\tErrNilCallback = stderrors.New(\"Callback cannot be nil\")\n\n\t// ErrEncryptionKeyMismatch is returned when the storage key is not\n\t// matched with the key previously given.\n\tErrEncryptionKeyMismatch = stderrors.New(\"Encryption key mismatch\")\n\n\t// ErrInvalidDataKeyID is returned if the datakey id is invalid.\n\tErrInvalidDataKeyID = stderrors.New(\"Invalid datakey id\")\n\n\t// ErrInvalidEncryptionKey is returned if length of encryption keys is invalid.\n\tErrInvalidEncryptionKey = stderrors.New(\"Encryption key's length should be\" +\n\t\t\"either 16, 24, or 32 bytes\")\n\t// ErrGCInMemoryMode is returned when db.RunValueLogGC is called in in-memory mode.\n\tErrGCInMemoryMode = stderrors.New(\"Cannot run value log GC when DB is opened in InMemory mode\")\n\n\t// ErrGCInReadOnlyMode is returned when db.RunValueLogGC is called in read-only mode.\n\tErrGCInReadOnlyMode = stderrors.New(\"Cannot run value log GC when DB is opened in ReadOnly mode\")\n\n\t// ErrDBClosed is returned when a get operation is performed after closing the DB.","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L79-L115","documentation":"ErrNilCallback is a sentinel guard error returned by DB.Subscribe when the caller supplies a nil callback function. Since subscription events are delivered by invoking cb for each KVList, a nil cb would panic inside the streaming loop, so the function validates it up front and refuses to start the subscription. The input at fault is the cb parameter; matches are irrelevant to this check.","triggerScenarios":"Calling db.Subscribe(ctx, nil, matches) — passing an untyped nil or a nil function variable as the cb argument.","commonSituations":"Building subscription registration from config/dependency injection where the callback wasn't wired; passing nil conditionally when a feature flag disables subscription handling.","solutions":["Pass a non-nil func(kv *KVList) error to Subscribe","If subscription is optional, guard the call: only invoke Subscribe when the callback is set","Return/log a config error at startup when the callback dependency is missing"],"exampleFix":"// before\ndb.Subscribe(ctx, nil, matches)\n// after\nif cb != nil {\n    err := db.Subscribe(ctx, cb, matches)\n}","handlingStrategy":"validation","validationCode":"if cb == nil { return errors.New(\"subscription callback must be provided\") }","typeGuard":null,"tryCatchPattern":"if err := db.Subscribe(ctx, cb, matches); err != nil {\n    if errors.Is(err, badger.ErrNilCallback) {\n        return fmt.Errorf(\"subscribe misconfigured: %w\", err)\n    }\n    return err\n}","preventionTips":["Never pass a bare nil callback; provide a no-op handler if events are ignored","Validate DI/config wiring at startup before calling Subscribe","Wrap Subscribe calls in helpers that assert the callback is non-nil"],"tags":["badger","api-misuse","nil-argument","subscriptions"],"backgroundTag":"nil-callback","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}