use netstack::netcore;
#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
pub enum Error {
#[error("internal operation returned an error")]
InternalFailure,
#[error("runtime degraded, component unreachable")]
RuntimeDegraded,
#[error("operation timed out")]
Timeout,
#[error("connection reset")]
ConnectionReset,
}
impl From<ts_runtime::Error> for Error {
fn from(value: ts_runtime::Error) -> Self {
match value.kind {
ts_runtime::ErrorKind::Timeout => Error::Timeout,
ts_runtime::ErrorKind::ActorGone => Error::RuntimeDegraded,
ts_runtime::ErrorKind::MailboxFull | ts_runtime::ErrorKind::ReplyErr => {
Error::InternalFailure
}
}
}
}
impl From<netcore::Error> for Error {
fn from(value: netcore::Error) -> Self {
match value {
netcore::Error::ChannelClosed => Error::RuntimeDegraded,
netcore::Error::WrongType
| netcore::Error::BadRequest
| netcore::Error::InvariantViolated => Error::InternalFailure,
netcore::Error::TcpStream(netcore::tcp::stream::Error::Reset) => Error::ConnectionReset,
}
}
}