Skip to main content

ruest/di/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum DiError {
5    #[error(
6        "[Ruest DI] Service `{type_name}` is not registered.\n\
7         Did you forget to add it to your module?\n\
8         \n\
9         Try:\n\
10         #[module(controllers = [...], providers = [{type_name}])]\n\
11         pub struct YourModule;\n\
12         \n\
13         And ensure `#[service]` is on `{type_name}` with `impl Default` or `register_provider`."
14    )]
15    NotFound { type_name: &'static str },
16
17    #[error("[Ruest DI] Circular dependency detected: {0}")]
18    CircularDependency(String),
19
20    #[error("[Ruest DI] Failed to resolve `{type_name}`: {reason}")]
21    ResolutionFailed {
22        type_name: &'static str,
23        reason: String,
24    },
25}
26
27impl DiError {
28    pub fn not_found<T: 'static>() -> Self {
29        Self::NotFound {
30            type_name: std::any::type_name::<T>(),
31        }
32    }
33}