From 118651055b7844e04aa5b89023c385e483de305f Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 31 Jan 2023 21:44:05 +0100 Subject: fix: remove unwrap from generated implementations of Injectable --- macros/src/injectable/implementation.rs | 14 ++++++++++---- src/errors/injectable.rs | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs index e81dd2d..30132bf 100644 --- a/macros/src/injectable/implementation.rs +++ b/macros/src/injectable/implementation.rs @@ -430,10 +430,16 @@ impl InjectableImpl }; Ok(quote! { - #do_method_call.map_err(|err| #resolve_failed_error { - reason: Box::new(err), - affected: self_type_name - })?.#to_ptr().unwrap() + #do_method_call + .map_err(|err| #resolve_failed_error { + reason: Box::new(err), + affected: self_type_name + })? + .#to_ptr() + .map_err(|err| InjectableError:: PrepareDependencyFailed { + reason: err, + dependency_name: #dep_interface_str + })? }) } diff --git a/src/errors/injectable.rs b/src/errors/injectable.rs index f132063..f040062 100644 --- a/src/errors/injectable.rs +++ b/src/errors/injectable.rs @@ -4,6 +4,7 @@ use crate::dependency_history::DependencyHistory; use crate::errors::di_container::DIContainerError; +use crate::errors::ptr::SomePtrError; /// Error type for structs that implement [`Injectable`]. /// @@ -42,4 +43,16 @@ pub enum InjectableError /// History of dependencies. dependency_history: DependencyHistory, }, + + /// Failed to prepare a dependency. + #[error("Failed to prepare dependency '{dependency_name}'")] + PrepareDependencyFailed + { + /// Error reason. + #[source] + reason: SomePtrError, + + /// The name of the dependency. + dependency_name: &'static str, + }, } -- cgit v1.2.3-18-g5258