Skip to main content

rpytest_daemon/
error.rs

1//! Error types for the rpytest daemon.
2
3use rpytest_ipc::transport::IpcError;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum DaemonError {
8    #[cfg(feature = "embedded-python")]
9    #[error("Python error: {0}")]
10    Python(String),
11
12    #[error("IO error: {0}")]
13    Io(#[from] std::io::Error),
14
15    #[error("Serialization error: {0}")]
16    Serialization(#[from] rmp_serde::encode::Error),
17
18    #[error("Deserialization error: {0}")]
19    Deserialization(#[from] rmp_serde::decode::Error),
20
21    #[error("Storage error: {0}")]
22    Storage(#[from] sled::Error),
23
24    #[error("IPC error: {0}")]
25    Ipc(#[from] IpcError),
26
27    #[error("Framing error: {0}")]
28    Framing(#[from] rpytest_ipc::framing::FramingError),
29
30    #[error("NNG error: {0}")]
31    Nng(#[from] nng::Error),
32
33    #[error("Context not found: {0}")]
34    ContextNotFound(String),
35
36    #[error("Invalid request: {0}")]
37    InvalidRequest(String),
38
39    #[error("Collection failed: {0}")]
40    CollectionFailed(String),
41
42    #[error("Python execution failed: {0}")]
43    PythonExecution(String),
44
45    #[error("Timeout: {0}")]
46    Timeout(String),
47
48    #[error("JSON error: {0}")]
49    Json(#[from] serde_json::Error),
50
51    #[error("AST parsing error: {0}")]
52    AstParsing(String),
53
54    #[error("Watcher error: {0}")]
55    Watcher(#[from] notify::Error),
56
57    #[error("Walkdir error: {0}")]
58    Walkdir(#[from] walkdir::Error),
59
60    #[error("Other error: {0}")]
61    Other(String),
62}
63
64pub type Result<T> = std::result::Result<T, DaemonError>;
65
66#[cfg(feature = "embedded-python")]
67impl From<pyo3::PyErr> for DaemonError {
68    fn from(err: pyo3::PyErr) -> Self {
69        DaemonError::Python(err.to_string())
70    }
71}