Skip to main content

nidus_core/error/
mod.rs

1//! Framework error types.
2
3/// Convenient result type for Nidus operations.
4pub type Result<T> = std::result::Result<T, NidusError>;
5
6/// Errors emitted by Nidus core primitives.
7#[derive(Debug, thiserror::Error)]
8pub enum NidusError {
9    /// A dependency was requested but no provider exists for its concrete type.
10    #[error("missing provider for type `{type_name}`")]
11    MissingProvider {
12        /// Rust type name requested from the container.
13        type_name: &'static str,
14    },
15
16    /// A provider was registered more than once for the same concrete type.
17    #[error("duplicate provider for type `{type_name}`")]
18    DuplicateProvider {
19        /// Rust type name registered more than once.
20        type_name: &'static str,
21    },
22
23    /// A request-scoped provider was resolved outside an explicit request scope.
24    #[error("request-scoped provider `{type_name}` must be resolved through RequestScope")]
25    RequestScopeRequired {
26        /// Rust type name requested from the root container.
27        type_name: &'static str,
28    },
29
30    /// A provider factory recursively requested a provider already being built.
31    #[error("circular provider resolution detected for type `{type_name}`")]
32    CircularProviderResolution {
33        /// Rust type name that was requested recursively.
34        type_name: &'static str,
35    },
36
37    /// A module was registered more than once with the same name.
38    #[error("duplicate module `{module}`")]
39    DuplicateModule {
40        /// Module name registered more than once.
41        module: String,
42    },
43
44    /// A module declares the same provider more than once.
45    #[error("module `{module}` declares duplicate provider `{provider}`")]
46    DuplicateModuleProvider {
47        /// Module declaring the duplicate provider.
48        module: String,
49        /// Provider name declared more than once.
50        provider: String,
51    },
52
53    /// A module declares the same controller more than once.
54    #[error("module `{module}` declares duplicate controller `{controller}`")]
55    DuplicateModuleController {
56        /// Module declaring the duplicate controller.
57        module: String,
58        /// Controller name declared more than once.
59        controller: String,
60    },
61
62    /// A module declares the same type name as both a provider and a controller.
63    #[error("module `{module}` declares `{type_name}` as both provider and controller")]
64    ModuleProviderControllerConflict {
65        /// Module declaring the conflicting metadata.
66        module: String,
67        /// Type name declared in both metadata sections.
68        type_name: String,
69    },
70
71    /// A module imports the same module more than once.
72    #[error("module `{module}` imports `{import}` more than once")]
73    DuplicateModuleImport {
74        /// Module declaring the duplicate import.
75        module: String,
76        /// Imported module named more than once.
77        import: String,
78    },
79
80    /// A module exports the same provider more than once.
81    #[error("module `{module}` exports `{provider}` more than once")]
82    DuplicateModuleExport {
83        /// Module declaring the duplicate export.
84        module: String,
85        /// Provider export named more than once.
86        provider: String,
87    },
88
89    /// A registered provider factory returned an error.
90    #[error("provider factory failed for type `{type_name}`: {source}")]
91    ProviderFactory {
92        /// Rust type name whose factory failed.
93        type_name: &'static str,
94        /// Underlying framework error.
95        #[source]
96        source: Box<NidusError>,
97    },
98
99    /// A module imports another module that is not present in the graph.
100    #[error("module `{module}` imports missing module `{import}`")]
101    MissingModuleImport {
102        /// Module declaring the import.
103        module: String,
104        /// Missing imported module.
105        import: String,
106    },
107
108    /// A circular module import chain was detected.
109    #[error("circular module import detected: {}", cycle.join(" -> "))]
110    CircularModuleImport {
111        /// Ordered cycle path.
112        cycle: Vec<String>,
113    },
114
115    /// A module exports a provider it does not own.
116    #[error("module `{module}` exports missing local provider `{provider}`")]
117    MissingProviderExport {
118        /// Module declaring the export.
119        module: String,
120        /// Provider missing from the module's provider list.
121        provider: String,
122    },
123
124    /// A module declares a local provider that is also exported by one of its imports.
125    #[error(
126        "module `{module}` declares provider `{provider}` that conflicts with export from `{import}`"
127    )]
128    ProviderVisibilityConflict {
129        /// Module with the conflicting provider visibility.
130        module: String,
131        /// Provider name declared locally and exported by an import.
132        provider: String,
133        /// Imported module exporting the same provider name.
134        import: String,
135    },
136
137    /// A module can see multiple providers with the same name through imports.
138    #[error(
139        "module `{module}` has ambiguous provider `{provider}` from imports: {}",
140        imports.join(", ")
141    )]
142    AmbiguousProvider {
143        /// Module with ambiguous visibility.
144        module: String,
145        /// Provider name that is visible from more than one import.
146        provider: String,
147        /// Imports exporting the same provider.
148        imports: Vec<String>,
149    },
150
151    /// A lifecycle startup hook failed after one or more hooks may have started.
152    #[error("lifecycle startup failed: {source}")]
153    LifecycleStartup {
154        /// Original startup failure.
155        #[source]
156        source: Box<NidusError>,
157        /// Shutdown failures encountered while rolling back already-started hooks.
158        rollback_errors: Vec<NidusError>,
159    },
160
161    /// Application composition failed during high-level bootstrap.
162    #[error("application build failed: {message}")]
163    ApplicationBuild {
164        /// Human-readable build failure.
165        message: String,
166    },
167}