krpc_client/error.rs
1use std::{io, sync::PoisonError};
2
3use thiserror::Error;
4
5/// The `RpcError` error indicates a failure originating
6/// from the server or from the client internally.
7#[derive(Error, Debug)]
8pub enum RpcError {
9 /// `Connection` indicates the client was unable to
10 /// connect to the server.
11 #[error("Connection failed")]
12 Connection(#[from] io::Error),
13
14 /// `Client` errors capture runtime errors from within
15 /// the client.
16 #[error("Unexpected client error")]
17 Client,
18
19 /// `Encoding` errors arise from failures to encode
20 /// messages for transmission to the server.
21 #[error("Encoding error: {0}")]
22 Encoding(String),
23
24 /// `ProtobufError` indicates an error parsing server
25 /// messages.
26 #[error(transparent)]
27 ProtobufError(#[from] protobuf::Error),
28}
29
30impl<T> From<PoisonError<T>> for RpcError {
31 fn from(_: PoisonError<T>) -> Self {
32 RpcError::Client
33 }
34}