use crate::{bootstrap::AppBootstrapper, HttpError};
pub trait AppBootstrap {
fn bootstrap() -> BootstrapResult<AppBootstrapper>;
}
#[derive(Debug, thiserror::Error)]
pub enum BootstrapError {
#[error("Module discovery failed: {message}")]
ModuleDiscoveryFailed { message: String },
#[error("Circular dependency detected: {cycle:?}")]
CircularDependency { cycle: Vec<String> },
#[error("Missing dependency: module '{module}' depends on '{dependency}' which is not registered")]
MissingDependency { module: String, dependency: String },
#[error("Module registration failed: {message}")]
ModuleRegistrationFailed { message: String },
#[error("Container configuration failed: {message}")]
ContainerConfigurationFailed { message: String },
#[error("Route registration failed: {message}")]
RouteRegistrationFailed { message: String },
#[error("Controller not found: '{controller_name}'. Available controllers: {available_controllers:?}")]
ControllerNotFound { controller_name: String, available_controllers: Vec<String> },
#[error("Controller registration failed: {message}")]
ControllerRegistrationFailed { message: String },
#[error("Controller metadata extraction failed: {message}")]
ControllerMetadataFailed { message: String },
#[error("Server startup failed: {message}")]
ServerStartupFailed { message: String },
#[error("HTTP error during bootstrap: {0}")]
HttpError(#[from] HttpError),
}
impl From<BootstrapError> for HttpError {
fn from(error: BootstrapError) -> Self {
match error {
BootstrapError::HttpError(http_error) => http_error,
_ => HttpError::InternalError { message: format!("Bootstrap failed: {}", error) },
}
}
}
pub type BootstrapResult<T> = Result<T, BootstrapError>;