{"record":{"id":"c261f83d0dd45678","repo":"benbjohnson/litestream","slug":"db-required","errorCode":null,"errorMessage":"db required","messagePattern":"db required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store.go","lineNumber":292,"sourceCode":"\t}\n\n\t// Cancel and wait for background tasks to complete.\n\ts.cancel()\n\ts.wg.Wait()\n\n\treturn err\n}\n\nfunc (s *Store) DBs() []*DB {\n\ts.mu.Lock()\n\tdefer s.mu.Unlock()\n\treturn slices.Clone(s.dbs)\n}\n\n// RegisterDB registers a new database with the store and starts monitoring it.\nfunc (s *Store) RegisterDB(db *DB) error {\n\tif db == nil {\n\t\treturn fmt.Errorf(\"db required\")\n\t}\n\n\t// First check: see if database already exists\n\ts.mu.Lock()\n\tfor _, existing := range s.dbs {\n\t\tif existing.Path() == db.Path() {\n\t\t\ts.mu.Unlock()\n\t\t\treturn nil\n\t\t}\n\t}\n\ts.mu.Unlock()\n\n\t// Apply store-wide settings before opening the database.\n\tdb.SetLogger(s.Logger.With(LogKeyDB, filepath.Base(db.Path())))\n\tdb.L0Retention = s.L0Retention\n\tdb.ShutdownSyncTimeout = s.ShutdownSyncTimeout\n\tdb.ShutdownSyncInterval = s.ShutdownSyncInterval\n\tdb.VerifyCompaction = s.VerifyCompaction","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/store.go#L274-L310","documentation":"Store.RegisterDB validates that the supplied *DB pointer is non-nil and returns this error immediately otherwise. Registering a nil DB would panic later when the store iterates or opens it, so the guard converts the misuse into an explicit error. It is a programming error in the caller, not a runtime state issue.","triggerScenarios":"Calling store.RegisterDB(nil) directly, or code paths that construct a *DB which failed and left the variable nil before registration (e.g. NewDB returned nil on an earlier error that was ignored).","commonSituations":"Custom integrations or scripts driving the litestream library API that skip checking the error from DB construction; refactors that reorder initialization so registration happens before db assignment.","solutions":["Ensure the *DB returned by the DB constructor is non-nil before calling RegisterDB","Check the constructor's error return; fix the earlier failure that yielded a nil DB","Add a nil check at the call site as a defensive guard"],"exampleFix":"// before\nvar db *litestream.DB\nstore.RegisterDB(db) // \"db required\"\n\n// after\ndb, err := litestream.NewDB(path)\nif err != nil {\n    return err\n}\nif db == nil {\n    return fmt.Errorf(\"db construction returned nil\")\n}\nreturn store.RegisterDB(db)","handlingStrategy":"type-guard","validationCode":"if db == nil {\n    return fmt.Errorf(\"cannot register nil DB\")\n}","typeGuard":"func dbReady(db *litestream.DB) bool { return db != nil }","tryCatchPattern":"if err := store.RegisterDB(db); err != nil && err.Error() == \"db required\" {\n    // caller bug: nil DB; fix initialization, do not retry\n}","preventionTips":["Always check the error from DB constructors before registering","Never register a DB variable that could be nil on an error path","Add nil-check lint in code driving the litestream library API"],"tags":["api","nil","validation","store"],"backgroundTag":"null-argument","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}