{"record":{"id":"050949c7d7c0afbf","repo":"JuliusBrussee/caveman","slug":"open-sqlite-q-w","errorCode":null,"errorMessage":"open sqlite %q: %w","messagePattern":"open sqlite %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/ccr/store_sqlite.go","lineNumber":191,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif afterPrepare != nil {\n\t\tafterPrepare()\n\t}\n\tbefore, err := inspectSQLiteGeneration(canonicalPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdsn := SQLiteDSN(canonicalPath)\n\tif canonicalPath != \":memory:\" {\n\t\t// PrepareSQLitePathCanonical already created the file. Never recreate\n\t\t// it if it vanishes between preparation and the driver's open.\n\t\tdsn += \"&mode=rw\"\n\t}\n\tdb, err := sql.Open(\"sqlite\", dsn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"open sqlite %q: %w\", canonicalPath, err)\n\t}\n\t// One writer connection. With a single connection every statement serializes\n\t// in-process (no self-contention) while busy_timeout absorbs cross-process\n\t// contention; it is also mandatory for an in-memory DSN, where a second\n\t// pooled connection would be a second, empty database.\n\tdb.SetMaxOpenConns(1)\n\tdb.SetMaxIdleConns(1)\n\twalJournal := false\n\tif canonicalPath != \":memory:\" {\n\t\tif err := persistSQLiteWAL(db); err != nil {\n\t\t\tcloseSQLiteAfterOpenFailure(db, canonicalPath)\n\t\t\treturn nil, fmt.Errorf(\"configure sqlite journal: %w\", err)\n\t\t}\n\t\t// A filesystem that cannot back -shm (NFS, SMB, some roaming profiles)\n\t\t// leaves the DSN's journal_mode request unapplied. Requiring the WAL\n\t\t// sidecars there would report a perfectly good database as replaced.\n\t\tmode, err := sqliteJournalMode(db)\n\t\tif err != nil {","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/engine/ccr/store_sqlite.go#L173-L209","documentation":"This error wraps the failure of sql.Open(\"sqlite\", dsn) while opening the CCR store's SQLite database. It is thrown by openWithBudgetHooks after PrepareSQLitePathCanonical has prepared the file, so the driver itself rejected the DSN or failed to initialize. Note the store opens with mode=rw when the file already exists, so a missing file also surfaces here.","triggerScenarios":"Malformed DSN options appended by the store, the SQLite driver not registered (blank import of modernc.org/sqlite or mattn/go-sqlite3 missing), or the prepared database file vanishing between preparation and open while mode=rw forbids recreation.","commonSituations":"Deployments where the data directory is cleaned by another process between prepare and open; builds forgetting the driver side-effect import; corrupt or unreadable file permissions passed as canonicalPath.","solutions":["Ensure the SQLite driver is imported for its side effects (e.g. _ \"modernc.org/sqlite\") in the binary opening the store","Verify the canonical path exists and is writable before calling Open; recreate it via PrepareSQLitePath if it was deleted","Check that no other process is deleting/replacing the database file between preparation and open","Enable driver-level debug by unwrapping the wrapped %w error to see the underlying driver message"],"exampleFix":"// before\nimport (\n    \"database/sql\"\n)\n// after\nimport (\n    \"database/sql\"\n    _ \"modernc.org/sqlite\"\n)","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(dbPath); os.IsNotExist(err) {\n    return fmt.Errorf(\"ccr db %s must be prepared before Open\", dbPath)\n}","typeGuard":null,"tryCatchPattern":"store, err := ccr.Open(dbPath)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) { /* inspect underlying driver failure */ }\n    return fmt.Errorf(\"open ccr store: %w\", err)\n}","preventionTips":["Always blank-import the SQLite driver package","Prepare the path with PrepareSQLitePath before Open","Ensure the db file is not deleted between prepare and open","Run Open as a user with write access to the db directory"],"tags":["sqlite","database","file-open-failed"],"backgroundTag":"file-open-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}