coil-runtime 0.1.1

HTTP runtime and request handling for the Coil framework.
Documentation
use super::*;
use coil_template::TemplateModelError;
use std::path::PathBuf;

#[derive(Debug, Error)]
pub enum RuntimeBuildError {
    #[error(transparent)]
    Config(#[from] ConfigError),
    #[error(transparent)]
    Registration(#[from] RegistrationError),
    #[error(transparent)]
    Capability(#[from] CapabilityValidationError),
    #[error(transparent)]
    ModuleInstallation(#[from] ModuleInstallationError),
    #[error(transparent)]
    Data(#[from] DataModelError),
    #[error(transparent)]
    Route(#[from] RouteBuildError),
    #[error(transparent)]
    Observability(#[from] ObservabilityError),
    #[error(transparent)]
    Wasm(#[from] WasmModelError),
    #[error(transparent)]
    Jobs(#[from] JobsModelError),
    #[error(transparent)]
    Ops(#[from] OpsModelError),
    #[error(transparent)]
    Template(#[from] TemplateModelError),
    #[error("failed to read template source `{path}`: {message}")]
    TemplateSourceRead { path: String, message: String },
    #[error("failed to parse template source `{path}`: {message}")]
    TemplateSourceParse { path: String, message: String },
    #[error("failed to read storefront catalog `{path}`: {message}")]
    StorefrontCatalogRead { path: String, message: String },
    #[error("failed to parse storefront catalog `{path}`: {message}")]
    StorefrontCatalogParse { path: String, message: String },
    #[error("storefront catalog `{path}` is invalid: {message}")]
    StorefrontCatalogValidation { path: String, message: String },
    #[error("template source `{path}` uses unsupported directive `{directive}`")]
    TemplateSourceUnsupportedDirective { path: String, directive: String },
    #[error("customer app root `{path}` does not exist")]
    MissingCustomerAppRoot { path: String },
    #[error("customer app root `{path}` is not a directory")]
    CustomerAppRootNotDirectory { path: String },
    #[error("customer app templates directory `{path}` does not exist")]
    MissingTemplateTree { path: String },
    #[error("customer app templates directory `{path}` does not contain any `.html` templates")]
    EmptyTemplateTree { path: String },
    #[error("configured auth package `{configured}` does not match loaded package `{actual}`")]
    AuthPackageMismatch { configured: String, actual: String },
    #[error("linked customer plugin `{plugin_id}` is registered more than once")]
    DuplicateCustomerPlugin { plugin_id: String },
    #[error("failed to register linked customer plugin `{plugin_id}`: {message}")]
    CustomerPluginRegistration { plugin_id: String, message: String },
    #[error(
        "installed extension `{extension_id}` targets customer app `{actual}` but runtime config is `{configured}`"
    )]
    ExtensionCustomerAppMismatch {
        extension_id: String,
        configured: String,
        actual: String,
    },
    #[error("handler `{route}` is registered more than once")]
    DuplicateHandler { route: String },
    #[error("handler `{route}` does not match a registered route")]
    UnknownHandlerRoute { route: String },
    #[error(
        "extension slot `{surface}` for `{kind:?}` is declared by both `{first_module}` and `{second_module}`"
    )]
    DuplicateExtensionSlot {
        kind: ExtensionPointKind,
        surface: String,
        first_module: String,
        second_module: String,
    },
    #[error(
        "installed extension `{extension_id}` handler `{handler_id}` targets `{point}` surface `{surface}` without a declared slot"
    )]
    UnknownExtensionSlot {
        extension_id: String,
        handler_id: String,
        point: ExtensionPointKind,
        surface: String,
    },
    #[error(
        "job `{job}` is declared by both `{first_module}` and `{second_module}`; runtime job names must be unique"
    )]
    DuplicateRuntimeJobName {
        job: String,
        first_module: String,
        second_module: String,
    },
    #[error(
        "runtime data repository `{repository}` is declared by both `{first_module}` and `{second_module}`"
    )]
    DuplicateDataRepository {
        repository: String,
        first_module: String,
        second_module: String,
    },
    #[error("event subscription `{event}` in module `{module}` must target a declared job")]
    EventSubscriptionMissingJob { module: String, event: String },
    #[error("event subscription `{event}` in module `{module}` targets unknown job `{job}`")]
    UnknownEventSubscriptionJob {
        module: String,
        event: String,
        job: String,
    },
    #[error(
        "event subscription `{event}` in module `{module}` targets job `{job}` with trigger `{trigger:?}`; domain-event subscriptions must target domain-event jobs"
    )]
    EventSubscriptionTriggerMismatch {
        module: String,
        event: String,
        job: String,
        trigger: JobTriggerKind,
    },
    #[error(
        "customer app manifest enables modules not linked into the customer binary: {modules:?}"
    )]
    CustomerManifestMissingLinkedModules { modules: Vec<String> },
    #[error("customer app manifest `{path}` could not be loaded: {reason}")]
    CustomerManifestLoad { path: PathBuf, reason: String },
    #[error("customer-root runtime builder requires `with_customer_root(...)` before build or run")]
    CustomerRootNotConfigured,
}

#[derive(Debug, Error)]
pub enum RuntimeBootstrapError {
    #[error(transparent)]
    Build(#[from] RuntimeBuildError),
    #[error(transparent)]
    Server(#[from] RuntimeServerError),
    #[error("failed to resolve the current working directory: {0}")]
    CurrentDirectory(std::io::Error),
    #[error(
        "could not discover a platform config under `{app_root}`; set `COIL_CONFIG` or add `platform.toml` / `platform.dev.toml`"
    )]
    ConfigNotFound { app_root: PathBuf },
    #[error("platform config `{path}` could not be loaded: {reason}")]
    ConfigLoad { path: PathBuf, reason: String },
    #[error("customer app manifest `{path}` could not be loaded: {reason}")]
    ManifestLoad { path: PathBuf, reason: String },
    #[error("auth package `{package}` could not be loaded from `{app_root}`: {reason}")]
    AuthPackageLoad {
        package: String,
        app_root: PathBuf,
        reason: String,
    },
    #[error("required environment variable `{name}` is missing or empty")]
    MissingEnvironmentVariable { name: &'static str },
    #[error("failed to bind the customer server to `{bind}`: {reason}")]
    Bind { bind: String, reason: String },
    #[error("customer server exited with an error: {reason}")]
    Serve { reason: String },
}