diff --git a/lib/src/backend.rs b/lib/src/backend.rs index 9114ef9fc..961fff60d 100644 --- a/lib/src/backend.rs +++ b/lib/src/backend.rs @@ -212,7 +212,7 @@ pub enum BackendError { source: Box, }, #[error("Error: {0}")] - Other(String), + Other(Box), } pub type BackendResult = Result; diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index d192ec692..d8dbef827 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -52,7 +52,7 @@ pub enum GitBackendInitError { impl From for BackendError { fn from(err: GitBackendInitError) -> Self { - BackendError::Other(err.to_string()) + BackendError::Other(err.into()) } } @@ -66,7 +66,7 @@ pub enum GitBackendLoadError { impl From for BackendError { fn from(err: GitBackendLoadError) -> Self { - BackendError::Other(err.to_string()) + BackendError::Other(err.into()) } } @@ -148,7 +148,7 @@ impl GitBackend { Some(head) => Ok(head.clone()), None => { let table = self.extra_metadata_store.get_head().map_err(|err| { - BackendError::Other(format!("Failed to read non-git metadata: {err}")) + BackendError::Other(format!("Failed to read non-git metadata: {err}").into()) })?; *locked_head = Some(table.clone()); Ok(table) @@ -157,9 +157,9 @@ impl GitBackend { } fn read_extra_metadata_table_locked(&self) -> BackendResult<(Arc, FileLock)> { - self.extra_metadata_store - .get_head_locked() - .map_err(|err| BackendError::Other(format!("Failed to read non-git metadata: {err}"))) + self.extra_metadata_store.get_head_locked().map_err(|err| { + BackendError::Other(format!("Failed to read non-git metadata: {err}").into()) + }) } fn save_extra_metadata_table( @@ -171,7 +171,7 @@ impl GitBackend { .extra_metadata_store .save_table(mut_table) .map_err(|err| { - BackendError::Other(format!("Failed to write non-git metadata: {err}")) + BackendError::Other(format!("Failed to write non-git metadata: {err}").into()) })?; // Since the parent table was the head, saved table are likely to be new head. // If it's not, cache will be reloaded when entry can't be found. @@ -599,7 +599,7 @@ impl Backend for GitBackend { let message = &contents.description; if contents.parents.is_empty() { return Err(BackendError::Other( - "Cannot write a commit with no parents".to_string(), + "Cannot write a commit with no parents".into(), )); } let mut parents = vec![]; @@ -613,7 +613,7 @@ impl Backend for GitBackend { return Err(BackendError::Other( "The Git backend does not support creating merge commits with the root \ commit as one of the parents." - .to_string(), + .into(), )); } } else { @@ -891,7 +891,7 @@ mod tests { commit.parents = vec![]; assert_matches!( backend.write_commit(commit.clone()), - Err(BackendError::Other(message)) if message.contains("no parents") + Err(BackendError::Other(err)) if err.to_string().contains("no parents") ); // Only root commit as parent @@ -928,7 +928,7 @@ mod tests { commit.parents = vec![first_id, backend.root_commit_id().clone()]; assert_matches!( backend.write_commit(commit), - Err(BackendError::Other(message)) if message.contains("root commit") + Err(BackendError::Other(err)) if err.to_string().contains("root commit") ); } diff --git a/lib/src/local_backend.rs b/lib/src/local_backend.rs index 809c00bab..352dc515a 100644 --- a/lib/src/local_backend.rs +++ b/lib/src/local_backend.rs @@ -37,19 +37,19 @@ const CHANGE_ID_LENGTH: usize = 16; impl From for BackendError { fn from(err: std::io::Error) -> Self { - BackendError::Other(err.to_string()) + BackendError::Other(err.into()) } } impl From for BackendError { fn from(err: PersistError) -> Self { - BackendError::Other(err.to_string()) + BackendError::Other(err.into()) } } impl From for BackendError { fn from(err: prost::DecodeError) -> Self { - BackendError::Other(err.to_string()) + BackendError::Other(err.into()) } }