{"record":{"id":"61edccc40c9bf9ea","repo":"benbjohnson/litestream","slug":"open-database-for-integrity-check-w","errorCode":null,"errorMessage":"open database for integrity check: %w","messagePattern":"open database for integrity check: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"replica.go","lineNumber":1339,"sourceCode":"\tdb, err := sql.Open(\"sqlite\", dbPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() { _ = db.Close() }()\n\n\t_, err = db.Exec(\"PRAGMA wal_checkpoint(TRUNCATE)\")\n\treturn err\n}\n\n// checkIntegrity runs a SQLite integrity check on the database at dbPath.\nfunc checkIntegrity(ctx context.Context, dbPath string, mode IntegrityCheckMode) error {\n\tif mode == IntegrityCheckNone {\n\t\treturn nil\n\t}\n\n\tdb, err := sql.Open(\"sqlite\", dbPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open database for integrity check: %w\", err)\n\t}\n\tdefer func() { _ = db.Close() }()\n\n\tvar pragma string\n\tswitch mode {\n\tcase IntegrityCheckQuick:\n\t\tpragma = \"quick_check\"\n\tcase IntegrityCheckFull:\n\t\tpragma = \"integrity_check\"\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported integrity check mode: %d\", mode)\n\t}\n\n\tvar result string\n\tif err := db.QueryRowContext(ctx, \"PRAGMA \"+pragma).Scan(&result); err != nil {\n\t\treturn fmt.Errorf(\"integrity check: %w\", err)\n\t}\n\tif result != \"ok\" {","sourceCodeStart":1321,"sourceCodeEnd":1357,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/replica.go#L1321-L1357","documentation":"checkIntegrity opens the restored database with database/sql using the 'sqlite' driver (modernc.org/sqlite) to run a PRAGMA check. This error wraps a failure at sql.Open, i.e. the driver could not be used to open the file. Since Open is lazy, this usually surfaces as driver registration rather than file problems.","triggerScenarios":"Restore/RestoreV3 with IntegrityCheck set (or tests TestCheckIntegrity_*) where sql.Open(\"sqlite\", dbPath) returns an error — most commonly because the modernc.org/sqlite driver was never registered (blank import missing) or the driver name was changed.","commonSituations":"Embedding Litestream as a library and importing a different SQLite driver; a build dropping the modernc dependency; custom builds using CGO sqlite drivers that register under the name 'sqlite' twice or not at all.","solutions":["Ensure modernc.org/sqlite is imported (blank import: _ \"modernc.org/sqlite\") so the 'sqlite' driver registers.","Check sql.Drivers() at startup for the 'sqlite' driver name.","If using another driver, rebuild Litestream unmodified — it requires modernc.org/sqlite.","Verify the module's go.mod still includes modernc.org/sqlite after vendoring/dependency updates."],"exampleFix":"// before\nimport (\n    \"database/sql\"\n)\n// after\nimport (\n    \"database/sql\"\n    _ \"modernc.org/sqlite\"\n)","handlingStrategy":"validation","validationCode":"import (\n    \"database/sql\"\n    _ \"modernc.org/sqlite\"\n)\nfunc sqliteDriverReady() bool {\n    for _, d := range sql.Drivers() {\n        if d == \"sqlite\" { return true }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"if err := replica.Restore(ctx, opt); err != nil && strings.Contains(err.Error(), \"open database for integrity check\") {\n    // fix driver import and retry\n}","preventionTips":["Blank-import modernc.org/sqlite in any binary embedding Litestream","Assert the 'sqlite' driver is registered at startup","Avoid mixing CGO SQLite drivers that collide on the 'sqlite' name","Pin modernc.org/sqlite in go.mod during dependency upgrades"],"tags":["sqlite","driver","integrity-check","dependency"],"backgroundTag":"missing-dependency","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"}