frame-core 0.3.0

Component model, lifecycle, process isolation — hosts components as supervised BEAM process trees
Documentation
//! Typed refusals and failures from the composed component runtime.

use thiserror::Error;

use crate::composition::SchedulerCompositionError;

/// A typed refusal or failure from [`crate::runtime::ComponentRuntime`] or
/// [`crate::runtime::mailbox_integer`].
#[derive(Debug, Error)]
pub enum RuntimeError {
    /// The policy asked for zero scheduler threads. beamr would silently
    /// substitute the machine's parallelism; the wrapper refuses instead —
    /// policy values are stated, never defaulted.
    #[error("runtime policy declares zero scheduler threads; state a positive thread count")]
    ZeroSchedulerThreads,
    /// The policy asked for a zero operation timeout, which would make every
    /// spawn, mailbox round-trip, and tombstone observation time out
    /// immediately.
    #[error("runtime policy declares a zero operation timeout; state a positive deadline")]
    ZeroOperationTimeout,
    /// Scheduler composition (BIF population + construction) failed.
    #[error("scheduler composition failed")]
    Composition {
        /// Exact typed composition refusal.
        #[source]
        source: SchedulerCompositionError,
    },
    /// The runtime refused or failed to hot-load a support module.
    #[error("support module load failed: {detail}")]
    SupportModuleLoad {
        /// Exact loader refusal.
        detail: String,
    },
    /// A support module vanished from the committed table immediately after
    /// its hot load reported success.
    #[error("support module {module} was absent immediately after hot load")]
    SupportModuleAbsent {
        /// Module whose committed entry was missing.
        module: String,
    },
    /// A freshly loaded support module's committed import table still defers
    /// `erlang:*` entries — process-fatal at first dispatch, refused up
    /// front (the same wall the registry applies to component bytecode).
    #[error("support module {module} left erlang:* imports deferred: {imports}")]
    SupportModuleDeferredBifImports {
        /// Refused module.
        module: String,
        /// The deferred `erlang:name/arity` entries.
        imports: String,
    },
    /// A retained old generation of a support module could not be safely
    /// purged during unload.
    #[error("failed to purge support module {module}: {detail}")]
    SupportModulePurge {
        /// Module whose old generation resisted the purge.
        module: String,
        /// Exact beamr purge refusal.
        detail: String,
    },
    /// Deleting a support module's current generation failed — the module
    /// was not loaded (a stale handle) or still had unpurged old code.
    #[error("failed to delete support module {module} during unload")]
    SupportModuleDelete {
        /// Module the delete step refused.
        module: String,
    },
    /// A support module was still committed after its verified unload — the
    /// runtime never reports an unload it cannot prove.
    #[error("support module {module} remained loaded after unload")]
    SupportModuleStillLoaded {
        /// Module still present after purge + delete.
        module: String,
    },
    /// Final teardown was refused because the process tree still has residue;
    /// every component must complete its ordered stop first.
    #[error("shutdown refused: {count} live scheduler process(es) remain after ordered stop")]
    ProcessResidue {
        /// Processes still alive on the scheduler.
        count: usize,
    },
    /// The reserved bound handed to [`crate::runtime::mailbox_integer`] lies
    /// outside the mailbox integer domain, leaving no valid value to fold
    /// into.
    #[error(
        "mailbox reserved bound {reserved_below} is outside the valid domain 0..={max}; \
         no mailbox integer can be derived above it"
    )]
    MailboxReservedRangeInvalid {
        /// The refused bound (every integer strictly below it is reserved).
        reserved_below: i64,
        /// The largest representable mailbox integer.
        max: i64,
    },
}