mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
index_store: use custom error type for write errors
Public APIs should use custom error types (not `io::Error` as here). The caller isn't affected by this commit because it just unwraps the error.
This commit is contained in:
parent
2cc15f40ef
commit
da1c259211
1 changed files with 17 additions and 3 deletions
|
@ -21,6 +21,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::backend::CommitId;
|
use crate::backend::CommitId;
|
||||||
use crate::commit::Commit;
|
use crate::commit::Commit;
|
||||||
|
@ -31,6 +32,12 @@ use crate::op_store::OperationId;
|
||||||
use crate::operation::Operation;
|
use crate::operation::Operation;
|
||||||
use crate::store::Store;
|
use crate::store::Store;
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum IndexWriteError {
|
||||||
|
#[error("{0}")]
|
||||||
|
Other(String),
|
||||||
|
}
|
||||||
|
|
||||||
pub struct IndexStore {
|
pub struct IndexStore {
|
||||||
dir: PathBuf,
|
dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -79,9 +86,16 @@ impl IndexStore {
|
||||||
&self,
|
&self,
|
||||||
index: MutableIndex,
|
index: MutableIndex,
|
||||||
op_id: &OperationId,
|
op_id: &OperationId,
|
||||||
) -> io::Result<Arc<ReadonlyIndex>> {
|
) -> Result<Arc<ReadonlyIndex>, IndexWriteError> {
|
||||||
let index = index.save_in(self.dir.clone())?;
|
let index = index.save_in(self.dir.clone()).map_err(|err| {
|
||||||
self.associate_file_with_operation(&index, op_id)?;
|
IndexWriteError::Other(format!("Failed to write commit index file: {err:?}"))
|
||||||
|
})?;
|
||||||
|
self.associate_file_with_operation(&index, op_id)
|
||||||
|
.map_err(|err| {
|
||||||
|
IndexWriteError::Other(format!(
|
||||||
|
"Failed to associate commit index file with a operation {op_id:?}: {err:?}"
|
||||||
|
))
|
||||||
|
})?;
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue