diff --git a/gitoxide-core/src/repository/diff.rs b/gitoxide-core/src/repository/diff.rs index 3608508142c..e90f777bec4 100644 --- a/gitoxide-core/src/repository/diff.rs +++ b/gitoxide-core/src/repository/diff.rs @@ -130,7 +130,7 @@ fn resolve_revspec( // We extract the error from the tree to learn the name, and treat it as file. let not_found = err .iter_frames() - .find_map(|f| f.downcast::()); + .find_map(|f| f.error().downcast_ref::()); if let Some(gix::refs::file::find::existing::Error::NotFound { name }) = not_found { let root = repo.workdir().map(ToOwned::to_owned); let name = gix::path::os_string_into_bstring(name.into())?; diff --git a/gix-error/src/error.rs b/gix-error/src/error.rs index 091dc1ccdaf..b82fe2a9915 100644 --- a/gix-error/src/error.rs +++ b/gix-error/src/error.rs @@ -6,13 +6,13 @@ impl Error { /// Return the error that is most likely the root cause, based on heuristics. /// Note that if there is nothing but this error, i.e. no source or children, this error is returned. pub fn probable_cause(&self) -> &(dyn std::error::Error + 'static) { - let root = self.inner.as_frame(); + let root = self.inner.frame(); root.probable_cause().unwrap_or(root).error() } /// Return an iterator over all errors in the tree in breadth-first order, starting with this one. pub fn iter_frames(&self) -> impl Iterator + '_ { - self.inner.as_frame().iter() + self.inner.frame().iter() } } @@ -22,7 +22,7 @@ pub(super) enum Inner { } impl Inner { - fn as_frame(&self) -> &exn::Frame { + fn frame(&self) -> &exn::Frame { match self { Inner::ExnAsError(f) | Inner::Exn(f) => f, } diff --git a/gix-error/src/exn/ext.rs b/gix-error/src/exn/ext.rs index c24e2c048dd..f6c6d3e1662 100644 --- a/gix-error/src/exn/ext.rs +++ b/gix-error/src/exn/ext.rs @@ -13,7 +13,6 @@ // limitations under the License. use crate::exn::Exn; -use std::error::Error; /// A trait bound of the supported error type of [`Exn`]. pub trait ErrorExt: std::error::Error + Send + Sync + 'static { @@ -37,7 +36,7 @@ pub trait ErrorExt: std::error::Error + Send + Sync + 'static { /// Raise this error as a new exception, with `sources` as causes. #[track_caller] - fn raise_iter(self, sources: I) -> Exn + fn raise_all(self, sources: I) -> Exn where Self: Sized, T: std::error::Error + Send + Sync + 'static, @@ -123,7 +122,7 @@ pub trait ResultExt { F: FnOnce() -> A; } -impl ResultExt for std::result::Result +impl ResultExt for Result where E: std::error::Error + Send + Sync + 'static, { @@ -153,14 +152,14 @@ where #[track_caller] fn or_raise_erased(self, err: F) -> Result where - A: Error + Send + Sync + 'static, + A: std::error::Error + Send + Sync + 'static, F: FnOnce() -> A, { self.or_raise(err).map_err(Exn::erased) } } -impl ResultExt for std::result::Result> +impl ResultExt for Result> where E: std::error::Error + Send + Sync + 'static, { @@ -190,7 +189,7 @@ where #[track_caller] fn or_raise_erased(self, err: F) -> Result where - A: Error + Send + Sync + 'static, + A: std::error::Error + Send + Sync + 'static, F: FnOnce() -> A, { self.or_raise(err).map_err(Exn::erased) diff --git a/gix-error/src/exn/impls.rs b/gix-error/src/exn/impls.rs index 436ceb8fa89..202e702ebc1 100644 --- a/gix-error/src/exn/impls.rs +++ b/gix-error/src/exn/impls.rs @@ -192,7 +192,7 @@ impl Exn { /// Iterate over all frames and find one that downcasts into error of type `T`. /// Note that the search includes this instance as well. pub fn downcast_any_ref(&self) -> Option<&T> { - self.iter().find_map(|e| e.downcast()) + self.iter().find_map(|e| e.error.downcast_ref()) } } @@ -307,11 +307,6 @@ impl Frame { &*self.error } - /// Try to downcast this error into the exact type T, or return `None` - pub fn downcast(&self) -> Option<&T> { - self.error.downcast_ref() - } - /// Return the source code location where this exception frame was created. pub fn location(&self) -> &'static Location<'static> { self.location diff --git a/gix-error/tests/error/exn.rs b/gix-error/tests/error/exn.rs index 6bcaf34f075..a9131f1e977 100644 --- a/gix-error/tests/error/exn.rs +++ b/gix-error/tests/error/exn.rs @@ -118,9 +118,9 @@ fn raise_chain() { } #[test] -fn raise_iter() { - let e = Error("Top").raise_iter( - (1..5).map(|idx| message!("E{}", idx).raise_iter((0..idx).map(|sidx| message!("E{}-{}", idx, sidx)))), +fn raise_all() { + let e = Error("Top").raise_all( + (1..5).map(|idx| message!("E{}", idx).raise_all((0..idx).map(|sidx| message!("E{}-{}", idx, sidx)))), ); insta::assert_debug_snapshot!(e, @r" Top @@ -257,7 +257,7 @@ fn raise_iter() { | └─ Message("SE2") "#); - let _this_should_compile = Error("Top-untyped").raise_iter((1..5).map(|idx| message!("E{}", idx).raise_erased())); + let _this_should_compile = Error("Top-untyped").raise_all((1..5).map(|idx| message!("E{}", idx).raise_erased())); assert_eq!( e.into_error().probable_cause().to_string(), @@ -381,7 +381,7 @@ fn error_tree() { ] "#); - let new_e = Error("E-New").raise_iter(err.drain_children()); + let new_e = Error("E-New").raise_all(err.drain_children()); insta::assert_debug_snapshot!(new_e, @r" E-New | diff --git a/gix-revision/src/spec/parse/function.rs b/gix-revision/src/spec/parse/function.rs index 10f9660ee91..45f99c4b5e3 100644 --- a/gix-revision/src/spec/parse/function.rs +++ b/gix-revision/src/spec/parse/function.rs @@ -480,7 +480,7 @@ where } }) }) - .ok_or_else(|| Error::new_with_input("couldn't parse revision", input).raise_iter(errors))?; + .ok_or_else(|| Error::new_with_input("couldn't parse revision", input).raise_all(errors))?; } input = {