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 tempfile::NamedTempFile;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::backend::CommitId;
|
||||
use crate::commit::Commit;
|
||||
|
@ -31,6 +32,12 @@ use crate::op_store::OperationId;
|
|||
use crate::operation::Operation;
|
||||
use crate::store::Store;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum IndexWriteError {
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
}
|
||||
|
||||
pub struct IndexStore {
|
||||
dir: PathBuf,
|
||||
}
|
||||
|
@ -79,9 +86,16 @@ impl IndexStore {
|
|||
&self,
|
||||
index: MutableIndex,
|
||||
op_id: &OperationId,
|
||||
) -> io::Result<Arc<ReadonlyIndex>> {
|
||||
let index = index.save_in(self.dir.clone())?;
|
||||
self.associate_file_with_operation(&index, op_id)?;
|
||||
) -> Result<Arc<ReadonlyIndex>, IndexWriteError> {
|
||||
let index = index.save_in(self.dir.clone()).map_err(|err| {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue