mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
## 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
41 lines
886 B
Rust
41 lines
886 B
Rust
use std::path::Path;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
#[error(
|
|
"failed to initialize sqlite local db at {}: {detail}",
|
|
database_path.display()
|
|
)]
|
|
pub struct LocalStateDbStartupError {
|
|
database_path: PathBuf,
|
|
detail: String,
|
|
#[source]
|
|
source: anyhow::Error,
|
|
}
|
|
|
|
impl LocalStateDbStartupError {
|
|
pub fn new(database_path: PathBuf, source: anyhow::Error) -> Self {
|
|
Self {
|
|
database_path,
|
|
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()
|
|
}
|
|
|
|
pub fn state_db_path(&self) -> &Path {
|
|
self.database_path()
|
|
}
|
|
|
|
pub fn detail(&self) -> &str {
|
|
self.detail.as_str()
|
|
}
|
|
}
|