Skip to main content

surfpool_sdk/
error.rs

1use std::fmt;
2
3pub type SurfnetResult<T> = Result<T, SurfnetError>;
4
5#[derive(Debug)]
6pub enum SurfnetError {
7    /// Failed to bind to a free port
8    PortAllocation(String),
9    /// The surfnet runtime failed to start
10    Startup(String),
11    /// The surfnet runtime thread panicked or exited unexpectedly
12    Runtime(String),
13    /// An RPC cheatcode call failed
14    Cheatcode(String),
15    /// The surfnet was shut down or aborted during startup
16    Aborted(String),
17}
18
19impl fmt::Display for SurfnetError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            SurfnetError::PortAllocation(msg) => write!(f, "port allocation failed: {msg}"),
23            SurfnetError::Startup(msg) => write!(f, "surfnet startup failed: {msg}"),
24            SurfnetError::Runtime(msg) => write!(f, "surfnet runtime error: {msg}"),
25            SurfnetError::Cheatcode(msg) => write!(f, "cheatcode failed: {msg}"),
26            SurfnetError::Aborted(msg) => write!(f, "surfnet aborted: {msg}"),
27        }
28    }
29}
30
31impl std::error::Error for SurfnetError {}