{"record":{"id":"6cc7efd59d36f111","repo":"zed-industries/zed","slug":"connection-initialization-retries-should-record-th","errorCode":null,"errorMessage":"connection initialization retries should record the last error","messagePattern":"connection initialization retries should record the last error","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/sqlez/src/thread_safe_connection.rs","lineNumber":230,"sourceCode":"                        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\n        // are from the background thread that can serialize them.\n        *connection.write.get_mut() = false;\n\n        connection\n    }\n}\n\nfn is_schema_lock_error(err: &anyhow::Error) -> bool {\n    let message = format!(\"{err:#}\");\n    message.contains(\"database schema is locked\") || message.contains(\"database is locked\")","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/sqlez/src/thread_safe_connection.rs#L212-L248","documentation":"During connection initialization, a non-schema-lock error occurred and the code asserts the retry loop always recorded a last_error before giving up; the panic fires when the invariant that every failure path stores its error was violated.","triggerScenarios":"Thrown at crates/sqlez/src/thread_safe_connection.rs:230 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Store the error in last_error on every failure branch","Report the recorded last_error to the caller instead of panicking","Distinguish schema-lock (retryable) errors from fatal ones"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}