aion-rs 0.27.0

Transport-agnostic Aion workflow engine with durability, replay, timers, and supervision.
Documentation
//! Typed errors for the workloop engine services.

use aion_core::{WorkflowId, WorkloopSpecError};
use aion_store::StoreError;

use crate::durability::DurabilityError;

/// Errors produced by the workloop services.
#[derive(thiserror::Error, Debug)]
pub enum WorkloopError {
    /// A declaration was invalid at the engine boundary (no assumed defaults:
    /// cadence, tolerance, and retention are declared or refused).
    #[error("workloop declaration refused: {0}")]
    Spec(#[from] WorkloopSpecError),

    /// The workloop store refused or failed an operation.
    #[error("workloop store failure: {0}")]
    Store(#[from] StoreError),

    /// The single-Recorder append path failed.
    #[error("workloop record failure: {0}")]
    Durability(#[from] DurabilityError),

    /// A loop id was expected to be registered and was not.
    #[error("workloop {loop_id} is not registered")]
    NotRegistered {
        /// The unregistered loop.
        loop_id: WorkflowId,
    },

    /// A loop was already registered under this id.
    #[error("workloop {loop_id} is already registered")]
    AlreadyRegistered {
        /// The already-registered loop.
        loop_id: WorkflowId,
    },

    /// The sweep interval was zero: the sweeper's clock is a declared value,
    /// never defaulted, and a zero interval is a busy-spin, not a cadence.
    #[error("workloop sweep interval must be greater than zero")]
    ZeroSweepInterval,

    /// A declared duration could not be represented on the engine clock.
    #[error("declared duration is not representable: {reason}")]
    UnrepresentableDuration {
        /// What overflowed.
        reason: String,
    },

    /// A health sample named an invariant the loop never declared.
    #[error("health sample names undeclared invariant `{invariant}` on loop {loop_id}")]
    UndeclaredInvariant {
        /// The loop the sample was fed to.
        loop_id: WorkflowId,
        /// The undeclared invariant name.
        invariant: String,
    },

    /// The engine seam refused an operation (recording, waking, spawning).
    #[error("engine seam failure: {reason}")]
    Engine {
        /// Human-readable seam failure reason.
        reason: String,
    },
}

impl From<WorkloopError> for crate::error::EngineError {
    fn from(error: WorkloopError) -> Self {
        Self::Runtime {
            reason: error.to_string(),
        }
    }
}