Skip to main content

exomonad_core/
error.rs

1//! Error types for exomonad.
2//!
3//! Provides typed errors for all failure modes, replacing anyhow with
4//! structured error handling.
5
6use std::io;
7use thiserror::Error;
8
9/// All error types that can occur in exomonad operations.
10#[derive(Debug, Error)]
11pub enum ExoMonadError {
12    /// JSON parse error while processing stream.
13    #[error("JSON parse error: {source}")]
14    JsonParse {
15        #[source]
16        source: serde_json::Error,
17    },
18
19    /// Failed to serialize result to JSON.
20    #[error("JSON serialize error: {0}")]
21    JsonSerialize(#[source] serde_json::Error),
22
23    /// Generic I/O error (for cases not covered above).
24    #[error("I/O error: {0}")]
25    Io(#[source] io::Error),
26
27    /// MCP server error.
28    #[error("MCP server error: {0}")]
29    McpServer(String),
30}
31
32/// Result type alias using ExoMonadError.
33pub type Result<T> = std::result::Result<T, ExoMonadError>;
34
35impl From<serde_json::Error> for ExoMonadError {
36    fn from(e: serde_json::Error) -> Self {
37        Self::JsonParse { source: e }
38    }
39}
40
41impl From<std::io::Error> for ExoMonadError {
42    fn from(e: std::io::Error) -> Self {
43        Self::Io(e)
44    }
45}