zed-industries/zed · error

connection initialization retries should record the last err

Error message

connection initialization retries should record the last error

What it means

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.

Source

Thrown at crates/sqlez/src/thread_safe_connection.rs:230

                        if is_schema_lock_error(&err)
                            && attempt + 1 < CONNECTION_INITIALIZE_RETRIES =>
                    {
                        last_error = Some(err);
                        thread::sleep(CONNECTION_INITIALIZE_RETRY_DELAY);
                        false
                    }
                    Err(err) => {
                        panic!(
                            "Initialize query failed to execute: {}\n\nCaused by:\n{err:#}",
                            initialize_query
                        )
                    }
                }
            });

            if !initialized {
                let err = last_error
                    .expect("connection initialization retries should record the last error");
                panic!(
                    "Initialize query failed to execute after retries: {}\n\nCaused by:\n{err:#}",
                    initialize_query
                );
            }
        }

        // Disallow writes on the connection. The only writes allowed for thread safe connections
        // are from the background thread that can serialize them.
        *connection.write.get_mut() = false;

        connection
    }
}

fn is_schema_lock_error(err: &anyhow::Error) -> bool {
    let message = format!("{err:#}");
    message.contains("database schema is locked") || message.contains("database is locked")

View on GitHub (pinned to f4178619ac)

Solutions

  1. Store the error in last_error on every failure branch
  2. Report the recorded last_error to the caller instead of panicking
  3. Distinguish schema-lock (retryable) errors from fatal ones
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/sqlez/src/thread_safe_connection.rs:230 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/6cc7efd59d36f111. Report an issue: GitHub.