aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-21 14:19:07 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 18:17:51 +0200
commit8c66b98bca6ed0a2990903fe8e0ea72def5c7be8 (patch)
treedeed78171051262dba7e8d97eba73a9aaf04dd5e /macros/src
parentb3e1b993b028bbfa73638236cfbdb50ee478d3f0 (diff)
refactor!: change errors to be more sane
BREAKING CHANGE: Major improvements have been made to error types and the error_stack crate is no longer used
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/injectable_impl.rs39
1 files changed, 17 insertions, 22 deletions
diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs
index d125f05..bc70be9 100644
--- a/macros/src/injectable_impl.rs
+++ b/macros/src/injectable_impl.rs
@@ -66,16 +66,13 @@ impl InjectableImpl
if #dependency_history_var.contains(&self_type_name) {
#dependency_history_var.push(self_type_name);
- return Err(
- report!(ResolveError)
- .attach_printable(format!(
- "Detected circular dependencies. {}",
- syrette::dependency_trace::create_dependency_trace(
- #dependency_history_var.as_slice(),
- self_type_name
- )
- ))
- );
+ let dependency_trace =
+ syrette::dependency_trace::create_dependency_trace(
+ #dependency_history_var.as_slice(),
+ self_type_name
+ );
+
+ return Err(InjectableError::DetectedCircular {dependency_trace });
}
#dependency_history_var.push(self_type_name);
@@ -92,26 +89,24 @@ impl InjectableImpl
fn resolve(
#di_container_var: &syrette::DIContainer,
mut #dependency_history_var: Vec<&'static str>,
- ) -> syrette::libs::error_stack::Result<
+ ) -> Result<
syrette::ptr::TransientPtr<Self>,
- syrette::errors::injectable::ResolveError>
+ syrette::errors::injectable::InjectableError>
{
- use syrette::libs::error_stack::{ResultExt, report};
- use syrette::errors::injectable::ResolveError;
+ use std::any::type_name;
+
+ use syrette::errors::injectable::InjectableError;
- let self_type_name = std::any::type_name::<#self_type>();
+ let self_type_name = type_name::<#self_type>();
#maybe_prevent_circular_deps
return Ok(syrette::ptr::TransientPtr::new(Self::new(
#(#get_dep_method_calls
- .change_context(ResolveError)
- .attach_printable(
- format!(
- "Unable to resolve a dependency of {}",
- self_type_name
- )
- )?
+ .map_err(|err| InjectableError::ResolveFailed {
+ reason: Box::new(err),
+ affected: self_type_name
+ })?
),*
)));
}