use crate::types::Address;
use async_std::io;
pub type Result<T> = std::result::Result<T, RatmanError>;
#[derive(Debug, thiserror::Error)]
pub enum RatmanError {
#[error("an i/o error: {0}")]
Io(#[from] io::Error),
#[cfg(feature = "proto")]
#[error("a base encoding error: {0}")]
Proto(#[from] protobuf::ProtobufError),
#[error("a json encoding error: {0}")]
Json(#[from] serde_json::error::Error),
#[cfg(feature = "client")]
#[error("a client API error: {0}")]
ClientApi(#[from] crate::ClientError),
#[cfg(feature = "netmod")]
#[error("a netmod error: {0}")]
Netmod(#[from] crate::NetmodError),
#[error("failed to acquire state directory lock")]
StateDirectoryAlreadyLocked,
#[error("failed to de-sequence a series of frames")]
DesequenceFault,
#[error("the given address '{0}' is unknown to this router!")]
NoSuchAddress(Address),
#[error("the address '{0}' already exists!")]
DuplicateAddress(Address),
#[error("the identifier data provided was not the correct length. Expected {0}, got {1}")]
WrongIdentifierLength(usize, usize),
}
impl From<RatmanError> for io::Error {
fn from(e: RatmanError) -> Self {
match e {
RatmanError::Io(e) => e,
e => panic!("unexpected IPC error: {}", e),
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum NonfatalError {
#[error("ratman is running ephemaral mode: no data will be persisted to disk!")]
IsEphemeral,
}