aboutsummaryrefslogtreecommitdiff
path: root/src/errors/injectable.rs
blob: f0400625f7f359f13057cdb8891762b7add13976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Error types for structs that implement [`Injectable`].
//!
//! [`Injectable`]: crate::interfaces::injectable::Injectable

use crate::dependency_history::DependencyHistory;
use crate::errors::di_container::DIContainerError;
use crate::errors::ptr::SomePtrError;

/// Error type for structs that implement [`Injectable`].
///
/// [`Injectable`]: crate::interfaces::injectable::Injectable
#[derive(thiserror::Error, Debug)]
pub enum InjectableError
{
    /// Failed to resolve dependencies.
    #[error("Failed to resolve a dependency of '{affected}'")]
    ResolveFailed
    {
        /// The reason for the problem.
        #[source]
        reason: Box<DIContainerError>,

        /// The affected injectable type.
        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_history}")]
    DetectedCircular
    {
        /// 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,
    },
}