Skip to main content

fluers_runtime/
error.rs

1//! Runtime error types.
2
3use thiserror::Error;
4
5/// A specialized [`Result`] for `fluers-runtime` operations.
6pub type RuntimeResult<T> = std::result::Result<T, RuntimeError>;
7
8/// Errors raised by the runtime harness layer.
9#[derive(Debug, Error)]
10pub enum RuntimeError {
11    /// An error originating in the core layer.
12    #[error(transparent)]
13    Core(#[from] fluers_core::CoreError),
14
15    /// A skill definition was malformed.
16    #[error("invalid skill: {0}")]
17    InvalidSkill(String),
18
19    /// A session was not found.
20    #[error("session not found: {0}")]
21    SessionNotFound(String),
22
23    /// A persistence operation failed.
24    #[error("persistence error: {0}")]
25    Persistence(String),
26
27    /// A tool name collided between two definitions.
28    #[error("tool name conflict: {0}")]
29    ToolNameConflict(String),
30
31    /// A sandbox operation failed.
32    #[error("sandbox error: {0}")]
33    Sandbox(String),
34
35    /// An I/O error.
36    #[error(transparent)]
37    Io(#[from] std::io::Error),
38
39    /// A file was too large for a non-truncating read (e.g. `edit`).
40    ///
41    /// Distinct from a truncated `read`: tools that must operate on the
42    /// complete file (write-back) get an error instead of silent data loss.
43    #[error("file `{path}` is {size} bytes, exceeds max {max} bytes")]
44    FileTooLarge {
45        /// The path that was too large (as supplied to the read call).
46        path: String,
47        /// The file's actual size in bytes.
48        size: usize,
49        /// The byte cap that was exceeded.
50        max: usize,
51    },
52}
53
54impl From<crate::persistence::PersistenceError> for RuntimeError {
55    fn from(error: crate::persistence::PersistenceError) -> Self {
56        match error {
57            crate::persistence::PersistenceError::Backend(message) => Self::Persistence(message),
58        }
59    }
60}