1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::mirror::MirrorError;
use crate::ProtocolError;
use gnitz_wire::WireFault;
use std::fmt;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub enum ClientError {
/// The transport failed, or a reply could not be decoded.
Protocol(ProtocolError),
/// A refusal, classified by the status a caller branches on — sent by the
/// server, or raised by a client-side check in the same terms.
Refused(WireFault),
/// The session's owner closed it; it accepts no further work.
Closed,
/// The connection failed: every request outstanding on it, and every later
/// one, carries this one cause.
ConnectionLost(ProtocolError),
/// A mirror store refused or failed. Kept as its own variant rather than
/// flattened to a message so [`MirrorError::Poisoned`] stays a class a host
/// can catch — a poisoned copy is recovered by
/// [`GnitzClient::close_mirror`](crate::GnitzClient::close_mirror) and by
/// nothing else.
Mirror(MirrorError),
/// The park hook aborted a blocking call — for the Python binding, a signal
/// handler raised. Carries the host's own error so the binding re-raises
/// exactly what the handler produced.
Interrupted(Arc<dyn std::error::Error + Send + Sync>),
}
impl From<ProtocolError> for ClientError {
fn from(e: ProtocolError) -> Self {
ClientError::Protocol(e)
}
}
impl From<std::io::Error> for ClientError {
fn from(e: std::io::Error) -> Self {
ClientError::Protocol(e.into())
}
}
/// A plain message is a `WireStatus::Error` refusal.
impl From<String> for ClientError {
fn from(e: String) -> Self {
ClientError::Refused(WireFault::from(e))
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ClientError::Protocol(e) => write!(f, "protocol error: {e}"),
ClientError::Refused(fault) => write!(f, "{fault}"),
ClientError::Closed => write!(f, "connection closed"),
ClientError::ConnectionLost(cause) => write!(f, "connection lost: {cause}"),
ClientError::Mirror(e) => write!(f, "{e}"),
ClientError::Interrupted(e) => write!(f, "interrupted: {e}"),
}
}
}
impl std::error::Error for ClientError {}