Skip to main content

sayiir_runtime/
error.rs

1//! Typed error for the sayiir runtime layer.
2
3use sayiir_core::error::{BoxError, WorkflowError};
4use sayiir_persistence::BackendError;
5
6/// Typed error for the sayiir runtime layer.
7///
8/// Replaces `BoxError` in internal runtime APIs, keeping `BoxError` only at
9/// true user boundaries (codec traits, user task callbacks).
10#[derive(Debug, thiserror::Error)]
11pub enum RuntimeError {
12    /// Workflow logic error (cancellation, definition mismatch, task not found, etc.)
13    #[error(transparent)]
14    Workflow(#[from] WorkflowError),
15
16    /// Persistent backend error (storage failures).
17    #[error(transparent)]
18    Backend(#[from] BackendError),
19
20    /// User task execution or codec error (opaque — from user-provided code).
21    #[error(transparent)]
22    Task(#[from] BoxError),
23
24    /// Tokio task join error (branch spawn failures).
25    #[error(transparent)]
26    Join(#[from] tokio::task::JoinError),
27}
28
29impl RuntimeError {
30    /// Returns `true` if this error is a `TaskTimedOut` workflow error.
31    #[must_use]
32    pub fn is_timeout(&self) -> bool {
33        matches!(self, Self::Workflow(WorkflowError::TaskTimedOut { .. }))
34    }
35}