mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +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
@@ -388,10 +388,7 @@ async fn init_state_db_for_app_server_target(
|
||||
AppServerTarget::Embedded => state_db::try_init(config).await.map(Some).map_err(|err| {
|
||||
let database_path = codex_state::runtime_db_path_for_corruption_error(&err)
|
||||
.unwrap_or_else(|| config.sqlite_config().state_db_path());
|
||||
std::io::Error::other(LocalStateDbStartupError::new(
|
||||
database_path,
|
||||
format!("{err:#}"),
|
||||
))
|
||||
std::io::Error::other(LocalStateDbStartupError::new(database_path, err))
|
||||
}),
|
||||
AppServerTarget::LocalDaemon { .. } | AppServerTarget::Remote { .. } => {
|
||||
Ok(state_db::get_state_db(config).await)
|
||||
@@ -3893,7 +3890,7 @@ requires_openai_auth = {requires_openai_auth}
|
||||
|
||||
assert_eq!(startup_error.database_path(), logs_db_path.as_path());
|
||||
assert!(
|
||||
codex_state::sqlite_error_detail_is_corruption(startup_error.detail()),
|
||||
startup_error.is_corruption(),
|
||||
"startup error should preserve the SQLite corruption cause, got: {}",
|
||||
startup_error.detail()
|
||||
);
|
||||
|
||||
@@ -9,16 +9,23 @@ use std::path::PathBuf;
|
||||
pub struct LocalStateDbStartupError {
|
||||
database_path: PathBuf,
|
||||
detail: String,
|
||||
#[source]
|
||||
source: anyhow::Error,
|
||||
}
|
||||
|
||||
impl LocalStateDbStartupError {
|
||||
pub fn new(database_path: PathBuf, detail: String) -> Self {
|
||||
pub fn new(database_path: PathBuf, source: anyhow::Error) -> Self {
|
||||
Self {
|
||||
database_path,
|
||||
detail,
|
||||
detail: format!("{source:#}"),
|
||||
source,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_corruption(&self) -> bool {
|
||||
codex_state::is_sqlite_corruption_error(&self.source)
|
||||
}
|
||||
|
||||
pub fn database_path(&self) -> &Path {
|
||||
self.database_path.as_path()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user