working_copy: use #[from] to slightly simplify error handling

This commit is contained in:
Martin von Zweigbergk 2022-05-23 16:59:12 -07:00 committed by Martin von Zweigbergk
parent ac82ad892e
commit 899325e94e

View file

@ -199,7 +199,7 @@ pub enum SnapshotError {
#[error("Symlink {path} target is not valid UTF-8")] #[error("Symlink {path} target is not valid UTF-8")]
InvalidUtf8SymlinkTarget { path: PathBuf, target: PathBuf }, InvalidUtf8SymlinkTarget { path: PathBuf, target: PathBuf },
#[error("Internal backend error: {0:?}")] #[error("Internal backend error: {0:?}")]
InternalBackendError(BackendError), InternalBackendError(#[from] BackendError),
} }
#[derive(Debug, Error, PartialEq, Eq)] #[derive(Debug, Error, PartialEq, Eq)]
@ -213,7 +213,7 @@ pub enum CheckoutError {
#[error("Concurrent checkout")] #[error("Concurrent checkout")]
ConcurrentCheckout, ConcurrentCheckout,
#[error("Internal error: {0:?}")] #[error("Internal error: {0:?}")]
InternalBackendError(BackendError), InternalBackendError(#[from] BackendError),
} }
#[derive(Debug, Error, PartialEq, Eq)] #[derive(Debug, Error, PartialEq, Eq)]
@ -223,7 +223,7 @@ pub enum ResetError {
#[error("Current checkout not found")] #[error("Current checkout not found")]
SourceNotFound, SourceNotFound,
#[error("Internal error: {0:?}")] #[error("Internal error: {0:?}")]
InternalBackendError(BackendError), InternalBackendError(#[from] BackendError),
} }
impl TreeState { impl TreeState {
@ -335,9 +335,7 @@ impl TreeState {
path: disk_path.to_path_buf(), path: disk_path.to_path_buf(),
err, err,
})?; })?;
self.store Ok(self.store.write_file(path, &mut Box::new(file))?)
.write_file(path, &mut Box::new(file))
.map_err(SnapshotError::InternalBackendError)
} }
fn write_symlink_to_store( fn write_symlink_to_store(
@ -358,9 +356,7 @@ impl TreeState {
path: disk_path.to_path_buf(), path: disk_path.to_path_buf(),
target: target.clone(), target: target.clone(),
})?; })?;
self.store Ok(self.store.write_symlink(path, str_target)?)
.write_symlink(path, str_target)
.map_err(SnapshotError::InternalBackendError)
} }
/// Look for changes to the working copy. If there are any changes, create /// Look for changes to the working copy. If there are any changes, create