Skip to main content

islands_core/
error.rs

1use std::fmt;
2
3#[derive(Debug)]
4pub enum CoreError {
5    Serialization(serde_json::Error),
6    InvalidInput(String),
7}
8
9impl fmt::Display for CoreError {
10    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11        match self {
12            CoreError::Serialization(e) => write!(f, "serialization error: {e}"),
13            CoreError::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
14        }
15    }
16}
17
18impl std::error::Error for CoreError {
19    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
20        match self {
21            CoreError::Serialization(e) => Some(e),
22            CoreError::InvalidInput(_) => None,
23        }
24    }
25}
26
27impl From<serde_json::Error> for CoreError {
28    fn from(e: serde_json::Error) -> Self {
29        CoreError::Serialization(e)
30    }
31}