use thiserror::Error;
#[derive(Debug, Error)]
pub enum RpcError {
#[error("rpc stream ended unexpectedly")]
Eof,
#[error("rpc protocol error: {0}")]
Protocol(String),
#[error("rpc aborted by peer (type {error_type}): {reason}")]
Abort {
reason: String,
error_type: u16,
},
#[error("rpc call failed remotely: {0}")]
RemoteCall(String),
#[error("rpc transport error: {0}")]
Io(#[from] std::io::Error),
}
impl From<capnp::Error> for RpcError {
fn from(error: capnp::Error) -> Self {
Self::Protocol(error.to_string())
}
}
impl From<capnp::NotInSchema> for RpcError {
fn from(error: capnp::NotInSchema) -> Self {
Self::Protocol(format!("value not in schema: {error:?}"))
}
}
impl From<std::str::Utf8Error> for RpcError {
fn from(error: std::str::Utf8Error) -> Self {
Self::Protocol(format!("invalid utf-8 in message: {error}"))
}
}
pub(crate) type Result<T> = std::result::Result<T, RpcError>;