Skip to main content

koi_runtime/
error.rs

1//! Runtime adapter errors.
2
3use koi_common::error::ErrorCode;
4
5#[derive(Debug, thiserror::Error)]
6pub enum RuntimeError {
7    #[error("runtime backend unavailable: {0}")]
8    BackendUnavailable(String),
9
10    #[error("runtime connection failed: {0}")]
11    Connection(String),
12
13    #[error("runtime event stream error: {0}")]
14    EventStream(String),
15
16    #[error("instance not found: {0}")]
17    NotFound(String),
18
19    #[error("runtime I/O error: {0}")]
20    Io(#[from] std::io::Error),
21
22    #[error("runtime internal error: {0}")]
23    Internal(String),
24}
25
26impl From<&RuntimeError> for ErrorCode {
27    fn from(e: &RuntimeError) -> Self {
28        match e {
29            RuntimeError::BackendUnavailable(_) => ErrorCode::CapabilityDisabled,
30            RuntimeError::NotFound(_) => ErrorCode::NotFound,
31            _ => ErrorCode::Internal,
32        }
33    }
34}