mirror of
https://github.com/openai/codex.git
synced 2026-12-06 01:10:58 +00:00
Classify SQLite corruption using typed error codes (#49710)
## What changed Preserve the underlying error in `LocalStateDbStartupError` and use its error chain to decide whether CLI startup failures qualify for automatic database backup and recovery. Replace corruption checks against error-message text with SQLite result-code classification, including SQLx extended result codes and directly wrapped `SqliteError` values. ## Testing Update the embedded startup corruption test to verify that the startup error retains a detectable SQLite corruption cause and the failed database path. GitOrigin-RevId: 6e8ecd0ee67f3c239183ddea3fc75c4e4cd5744a
This commit is contained in:
committed by
copyberry
parent
4f699cd642
commit
596ae94fb0
@@ -17,12 +17,8 @@ pub(crate) fn is_locked(detail: &str) -> bool {
|
||||
codex_state::sqlite_error_detail_is_lock(detail)
|
||||
}
|
||||
|
||||
pub(crate) fn is_corruption(detail: &str) -> bool {
|
||||
codex_state::sqlite_error_detail_is_corruption(detail)
|
||||
}
|
||||
|
||||
pub(crate) fn is_auto_backup_recoverable(startup_error: &LocalStateDbStartupError) -> bool {
|
||||
is_corruption(startup_error.detail()) || sqlite_home_is_blocking_file(startup_error)
|
||||
startup_error.is_corruption() || sqlite_home_is_blocking_file(startup_error)
|
||||
}
|
||||
|
||||
fn sqlite_home_is_blocking_file(startup_error: &LocalStateDbStartupError) -> bool {
|
||||
@@ -111,7 +107,7 @@ mod tests {
|
||||
tokio::fs::write(failed_db_path.as_path(), b"logs").await?;
|
||||
|
||||
let startup_error =
|
||||
LocalStateDbStartupError::new(failed_db_path.clone(), "corrupt".to_string());
|
||||
LocalStateDbStartupError::new(failed_db_path.clone(), anyhow::anyhow!("corrupt"));
|
||||
let backups = backup_files_for_fresh_start(&startup_error).await?;
|
||||
|
||||
assert_eq!(
|
||||
@@ -134,7 +130,7 @@ mod tests {
|
||||
tokio::fs::write(sqlite_home.as_path(), b"not-a-directory").await?;
|
||||
let sqlite = codex_state::SqliteConfig::new_for_testing(sqlite_home.as_path().abs());
|
||||
let startup_error =
|
||||
LocalStateDbStartupError::new(sqlite.state_db_path(), "File exists".to_string());
|
||||
LocalStateDbStartupError::new(sqlite.state_db_path(), anyhow::anyhow!("File exists"));
|
||||
|
||||
assert!(is_auto_backup_recoverable(&startup_error));
|
||||
let backups = backup_files_for_fresh_start(&startup_error).await?;
|
||||
|
||||
Reference in New Issue
Block a user