diff options
Diffstat (limited to 'src/errors')
-rw-r--r-- | src/errors/async_di_container.rs | 79 | ||||
-rw-r--r-- | src/errors/injectable.rs | 14 | ||||
-rw-r--r-- | src/errors/mod.rs | 3 | ||||
-rw-r--r-- | src/errors/ptr.rs | 18 |
4 files changed, 113 insertions, 1 deletions
diff --git a/src/errors/async_di_container.rs b/src/errors/async_di_container.rs new file mode 100644 index 0000000..4f5e50a --- /dev/null +++ b/src/errors/async_di_container.rs @@ -0,0 +1,79 @@ +//! Error types for [`AsyncDIContainer`] and it's related structs. +//! +//! --- +//! +//! *This module is only available if Syrette is built with the "async" feature.* +//! +//! [`AsyncDIContainer`]: crate::async_di_container::AsyncDIContainer + +use crate::errors::injectable::InjectableError; + +/// Error type for [`AsyncDIContainer`]. +/// +/// [`AsyncDIContainer`]: crate::async_di_container::AsyncDIContainer +#[derive(thiserror::Error, Debug)] +pub enum AsyncDIContainerError +{ + /// Unable to cast a binding for a interface. + #[error("Unable to cast binding for interface '{0}'")] + CastFailed(&'static str), + + /// Failed to resolve a binding for a interface. + #[error("Failed to resolve binding for interface '{interface}'")] + BindingResolveFailed + { + /// The reason for the problem. + #[source] + reason: InjectableError, + + /// The affected bound interface. + interface: &'static str, + }, + + /// No binding exists for a interface (and optionally a name). + #[error( + "No binding exists for interface '{interface}' {}", + .name.map_or_else(String::new, |name| format!("with name '{}'", name)) + )] + BindingNotFound + { + /// The interface that doesn't have a binding. + interface: &'static str, + + /// The name of the binding if one exists. + name: Option<&'static str>, + }, +} + +/// Error type for [`AsyncBindingBuilder`]. +/// +/// [`AsyncBindingBuilder`]: crate::async_di_container::AsyncBindingBuilder +#[derive(thiserror::Error, Debug)] +pub enum AsyncBindingBuilderError +{ + /// A binding already exists for a interface. + #[error("Binding already exists for interface '{0}'")] + BindingAlreadyExists(&'static str), +} + +/// Error type for [`AsyncBindingScopeConfigurator`]. +/// +/// [`AsyncBindingScopeConfigurator`]: crate::async_di_container::AsyncBindingScopeConfigurator +#[derive(thiserror::Error, Debug)] +pub enum AsyncBindingScopeConfiguratorError +{ + /// Resolving a singleton failed. + #[error("Resolving the given singleton failed")] + SingletonResolveFailed(#[from] InjectableError), +} + +/// Error type for [`AsyncBindingWhenConfigurator`]. +/// +/// [`AsyncBindingWhenConfigurator`]: crate::async_di_container::AsyncBindingWhenConfigurator +#[derive(thiserror::Error, Debug)] +pub enum AsyncBindingWhenConfiguratorError +{ + /// A binding for a interface wasn't found. + #[error("A binding for interface '{0}' wasn't found'")] + BindingNotFound(&'static str), +} diff --git a/src/errors/injectable.rs b/src/errors/injectable.rs index 4b9af96..ed161cb 100644 --- a/src/errors/injectable.rs +++ b/src/errors/injectable.rs @@ -3,7 +3,7 @@ //! //! [`Injectable`]: crate::interfaces::injectable::Injectable -use super::di_container::DIContainerError; +use crate::errors::di_container::DIContainerError; /// Error type for structs that implement [`Injectable`]. /// @@ -23,6 +23,18 @@ pub enum InjectableError affected: &'static str, }, + /// Failed to resolve dependencies. + #[cfg(feature = "async")] + #[error("Failed to resolve a dependency of '{affected}'")] + AsyncResolveFailed + { + /// The reason for the problem. + #[source] + reason: Box<crate::errors::async_di_container::AsyncDIContainerError>, + + /// The affected injectable type. + affected: &'static str, + }, /// Detected circular dependencies. #[error("Detected circular dependencies. {dependency_trace}")] DetectedCircular diff --git a/src/errors/mod.rs b/src/errors/mod.rs index 7d66ddf..c3930b0 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -3,3 +3,6 @@ pub mod di_container; pub mod injectable; pub mod ptr; + +#[cfg(feature = "async")] +pub mod async_di_container; diff --git a/src/errors/ptr.rs b/src/errors/ptr.rs index e0c3d05..56621c1 100644 --- a/src/errors/ptr.rs +++ b/src/errors/ptr.rs @@ -17,3 +17,21 @@ pub enum SomePtrError found: &'static str, }, } + +/// Error type for [`SomeThreadsafePtr`]. +/// +/// [`SomeThreadsafePtr`]: crate::ptr::SomeThreadsafePtr +#[derive(thiserror::Error, Debug)] +pub enum SomeThreadsafePtrError +{ + /// Tried to get as a wrong threadsafe smart pointer type. + #[error("Wrong threadsafe smart pointer type. Expected {expected}, found {found}")] + WrongPtrType + { + /// The expected smart pointer type. + expected: &'static str, + + /// The found smart pointer type. + found: &'static str, + }, +} |