Skip to main content

jsmpi/
error.rs

1use std::fmt::{Display, Formatter};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug)]
6pub enum Error {
7    RuntimeNotConfigured,
8    Unsupported(&'static str),
9    WouldBlock,
10    Timeout {
11        operation: &'static str,
12        timeout_ms: u64,
13    },
14    Serialization(String),
15    Protocol(String),
16}
17
18impl Display for Error {
19    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::RuntimeNotConfigured => write!(f, "jsmpi runtime is not configured"),
22            Self::Unsupported(message) => write!(f, "unsupported operation: {message}"),
23            Self::WouldBlock => write!(f, "operation would block in the current runtime"),
24            Self::Timeout {
25                operation,
26                timeout_ms,
27            } => write!(f, "{operation} timed out after {timeout_ms}ms"),
28            Self::Serialization(message) => write!(f, "serialization error: {message}"),
29            Self::Protocol(message) => write!(f, "protocol error: {message}"),
30        }
31    }
32}
33
34impl std::error::Error for Error {}