{"record":{"id":"aa3f984f5bc0804c","repo":"benbjohnson/litestream","slug":"open-database-w-aa3f98","errorCode":null,"errorMessage":"open database: %w","messagePattern":"open database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store.go","lineNumber":397,"sourceCode":"// The context is checked for cancellation before opening.\n// Note: db.Open() itself does not support cancellation.\nfunc (s *Store) EnableDB(ctx context.Context, path string) error {\n\tdb := s.FindDB(path)\n\tif db == nil {\n\t\treturn fmt.Errorf(\"database not found: %s\", path)\n\t}\n\n\tif db.IsOpen() {\n\t\treturn fmt.Errorf(\"database already enabled: %s\", path)\n\t}\n\n\t// Check for cancellation before starting open\n\tif err := ctx.Err(); err != nil {\n\t\treturn fmt.Errorf(\"enable database: %w\", err)\n\t}\n\n\tif err := db.Open(); err != nil {\n\t\treturn fmt.Errorf(\"open database: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// DisableDB stops replication for a database.\nfunc (s *Store) DisableDB(ctx context.Context, path string) error {\n\tdb := s.FindDB(path)\n\tif db == nil {\n\t\treturn fmt.Errorf(\"database not found: %s\", path)\n\t}\n\n\tif !db.IsOpen() {\n\t\treturn fmt.Errorf(\"database already disabled: %s\", path)\n\t}\n\n\tif err := db.Close(ctx); err != nil {\n\t\treturn fmt.Errorf(\"close database: %w\", err)","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/store.go#L379-L415","documentation":"EnableDB calls db.Open() to start replication; this error wraps any failure Open returns (SQLite open failure, replica client init, config problems). Note db.Open() does not support context cancellation, so once reached, the open runs to completion and its error is surfaced here.","triggerScenarios":"Store.EnableDB(ctx, path) where db.Open() fails: SQLite file missing/unreadable, directory not writable for WAL/SHM, bad replica configuration, or the DB was concurrently opened/closed.","commonSituations":"Wrong db path in the enable request; permissions changed after registration; replica storage credentials invalid; disk full or read-only filesystem preventing WAL creation.","solutions":["Read the wrapped cause from the error chain and fix the underlying open failure","Verify the SQLite file exists and the process has read/write access to it and its directory","Validate replica client config (bucket, credentials, endpoint) before enabling","Retry with backoff if the failure was transient (e.g. storage briefly unavailable)"],"exampleFix":"// before\nerr := store.EnableDB(ctx, path) // opaque open failure\n// after\nif err := store.EnableDB(ctx, path); err != nil {\n    log.Printf(\"enable %s failed: %v\", path, err) // prints wrapped cause\n}\n// ensure perms: chmod u+rw /path/to/app.db","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(dbPath); err != nil {\n    return fmt.Errorf(\"sqlite file inaccessible: %w\", err)\n}\nif f, err := os.OpenFile(dbPath, os.O_RDWR, 0); err != nil {\n    return fmt.Errorf(\"sqlite file not writable: %w\", err)\n} else { f.Close() }","typeGuard":null,"tryCatchPattern":"if err := store.EnableDB(ctx, path); err != nil {\n    if strings.Contains(err.Error(), \"open database:\") {\n        log.Printf(\"open failed: %v\", err) // wrapped root cause\n        // validate file, perms, replica config, then retry with backoff\n    }\n    return err\n}","preventionTips":["Verify the SQLite file and directory are read/write for the litestream process","Validate replica credentials and endpoints before enabling","Retry transient open failures with exponential backoff"],"tags":["database","open","configuration"],"backgroundTag":"file-open-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}