From f5301665b3a8aa77fa5ea6a431693d40116304df Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Tue, 26 Sep 2023 09:59:09 +0200 Subject: [PATCH] Reduce error size (#32) Resolves: #31 --- CHANGELOG.md | 3 +++ src/error.rs | 2 +- src/index/git_remote.rs | 11 +++-------- src/index/location.rs | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb5cb8f..f63cc47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Changed +- [PR#32](https://github.com/EmbarkStudios/tame-index/pull/32) resolved [#31](https://github.com/EmbarkStudios/tame-index/issues/31) by reducing the size of `Error`. + ## [0.6.0] - 2023-09-11 ### Changed - [PR#27](https://github.com/EmbarkStudios/tame-index/pull/27) updated `gix` to 0.53.1. Thanks [@Byron](https://github.com/Byron)! diff --git a/src/error.rs b/src/error.rs index 6e3a4f0..7c9bd4e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -32,7 +32,7 @@ pub enum Error { Json(#[from] serde_json::Error), /// Failed to deserialize TOML #[error(transparent)] - Toml(#[from] toml::de::Error), + Toml(#[from] Box), /// An index entry did not contain any versions #[error("index entry contained no versions for the crate")] NoCrateVersions, diff --git a/src/index/git_remote.rs b/src/index/git_remote.rs index 2326172..730e2c4 100644 --- a/src/index/git_remote.rs +++ b/src/index/git_remote.rs @@ -114,7 +114,8 @@ impl RemoteGitIndex { } else { let (repo, out) = gix::prepare_clone_bare(index.url.as_str(), &index.cache.path) .map_err(Box::new)? - .with_remote_name("origin")? + .with_remote_name("origin") + .map_err(Box::new)? .configure_remote(|remote| { Ok(remote.with_refspecs(["+HEAD:refs/remotes/origin/HEAD"], DIR)?) }) @@ -405,12 +406,6 @@ pub enum GitError { #[error(transparent)] Open(#[from] Box), #[error(transparent)] - Peel(#[from] gix::reference::peel::Error), - #[error(transparent)] - Head(#[from] gix::reference::head_commit::Error), - #[error(transparent)] - HeadUpdate(#[from] gix::reference::edit::Error), - #[error(transparent)] Commit(#[from] gix::object::commit::Error), #[error(transparent)] InvalidObject(#[from] gix::object::try_into::Error), @@ -423,7 +418,7 @@ pub enum GitError { #[error(transparent)] Lock(#[from] gix::lock::acquire::Error), #[error(transparent)] - RemoteName(#[from] gix::remote::name::Error), + RemoteName(#[from] Box), #[error(transparent)] Config(#[from] Box), #[error(transparent)] diff --git a/src/index/location.rs b/src/index/location.rs index cfd54ef..aa507af 100644 --- a/src/index/location.rs +++ b/src/index/location.rs @@ -211,7 +211,7 @@ pub(crate) fn read_cargo_config( Err(err) => return Err(Error::IoPath(err, path)), }; - let toml: toml::Value = toml::from_str(&contents)?; + let toml: toml::Value = toml::from_str(&contents).map_err(Box::new)?; if let Some(value) = callback(&toml) { return Ok(Some(value)); } @@ -233,7 +233,7 @@ pub(crate) fn read_cargo_config( let path = home.join("config.toml"); if path.exists() { let toml: toml::Value = - toml::from_str(&std::fs::read_to_string(&path)?).map_err(Error::Toml)?; + toml::from_str(&std::fs::read_to_string(&path)?).map_err(Box::new)?; if let Some(value) = callback(&toml) { return Ok(Some(value)); }