{"record":{"id":"6df7423990d3088c","repo":"zed-industries/zed","slug":"initialize-query-failed-to-execute-n-ncaused-b","errorCode":null,"errorMessage":"Initialize query failed to execute: {}\\n\\nCaused by:\\n{err:#}","messagePattern":"Initialize query failed to execute: (.+?)\\\\n\\\\nCaused by:\\\\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/sqlez/src/thread_safe_connection.rs","lineNumber":220,"sourceCode":"\n        if let Some(initialize_query) = connection_initialize_query {\n            let mut last_error = None;\n            let initialized = (0..CONNECTION_INITIALIZE_RETRIES).any(|attempt| {\n                match connection\n                    .exec(initialize_query)\n                    .and_then(|mut statement| statement())\n                {\n                    Ok(()) => true,\n                    Err(err)\n                        if is_schema_lock_error(&err)\n                            && attempt + 1 < CONNECTION_INITIALIZE_RETRIES =>\n                    {\n                        last_error = Some(err);\n                        thread::sleep(CONNECTION_INITIALIZE_RETRY_DELAY);\n                        false\n                    }\n                    Err(err) => {\n                        panic!(\n                            \"Initialize query failed to execute: {}\\n\\nCaused by:\\n{err:#}\",\n                            initialize_query\n                        )\n                    }\n                }\n            });\n\n            if !initialized {\n                let err = last_error\n                    .expect(\"connection initialization retries should record the last error\");\n                panic!(\n                    \"Initialize query failed to execute after retries: {}\\n\\nCaused by:\\n{err:#}\",\n                    initialize_query\n                );\n            }\n        }\n\n        // Disallow writes on the connection. The only writes allowed for thread safe connections","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/sqlez/src/thread_safe_connection.rs#L202-L238","documentation":"sqlez's ThreadSafeConnection runs an initialization SQL script each time it opens a SQLite connection (schema setup). It retries only when the error is a schema lock and attempts remain; every other SQLite error panics immediately with the SQL text and the full error chain (crates/sqlez/src/thread_safe_connection.rs:220). The chained 'Caused by:' entries carry the actual SQLite error code, which decides the fix.","triggerScenarios":"Opening a ThreadSafeConnection whose initialize query fails: SQLITE_CORRUPT (damaged database file), SQLITE_IOERR/SQLITE_FULL (disk failure or full disk), SQLITE_READONLY/permissions on the db file or its directory, a syntax error in the init SQL itself, or a lock error the retry loop does not classify as a schema lock.","commonSituations":"Zed's db.sqlite corrupted after a crash or kill; disk full; running from an unwritable HOME or read-only mount; a dev experiment shipping a bad migration query in the initialize script.","solutions":["Read the 'Caused by:' chain in the panic to get the SQLite error code — it selects the right fix below.","For corrupt/IO errors, quit the app and rename the database so it is recreated, e.g. mv ~/.config/Zed/db.sqlite ~/.config/Zed/db.sqlite.bak (path varies by channel/platform).","For permission errors, fix write permission on the config directory; for full disk, free space and relaunch.","If you wrote the initialize query, run it manually with the sqlite3 CLI against a scratch copy to catch SQL errors."],"exampleFix":"# before: startup panics with 'Initialize query failed to execute'\n\n# after: back up the damaged database and relaunch so it is recreated\nmv ~/.config/Zed/db.sqlite ~/.config/Zed/db.sqlite.bak","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run one application instance per database file.","Include the db file in backups; it can be renamed and regenerated safely.","Smoke-test migration SQL with the sqlite3 CLI before shipping it in an initialize query.","Ensure the config directory is writable and the disk has space before launch."],"tags":["sqlite","sqlez","database","startup","panic","zed"],"backgroundTag":"database-initialization-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}