1use thiserror::Error;
2
3#[derive(Debug, Error)]
5pub enum RpcError {
6 #[error("rpc stream ended unexpectedly")]
8 Eof,
9 #[error("rpc protocol error: {0}")]
11 Protocol(String),
12 #[error("rpc aborted by peer (type {error_type}): {reason}")]
14 Abort {
15 reason: String,
17 error_type: u16,
19 },
20 #[error("rpc call failed remotely: {0}")]
22 RemoteCall(String),
23 #[error("rpc transport error: {0}")]
25 Io(#[from] std::io::Error),
26}
27
28impl From<capnp::Error> for RpcError {
29 fn from(error: capnp::Error) -> Self {
30 Self::Protocol(error.to_string())
31 }
32}
33
34impl From<capnp::NotInSchema> for RpcError {
35 fn from(error: capnp::NotInSchema) -> Self {
36 Self::Protocol(format!("value not in schema: {error:?}"))
37 }
38}
39
40impl From<std::str::Utf8Error> for RpcError {
41 fn from(error: std::str::Utf8Error) -> Self {
42 Self::Protocol(format!("invalid utf-8 in message: {error}"))
43 }
44}
45
46pub(crate) type Result<T> = std::result::Result<T, RpcError>;