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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::jsonrpc;
use std::fmt;
#[derive(Clone, Debug, PartialEq)]
pub struct Mismatch<T> {
pub expected: T,
pub got: T,
}
impl<T: fmt::Display> fmt::Display for Mismatch<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_fmt(format_args!("Expected: {}, Got: {}", self.expected, self.got))
}
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Networking or low-level protocol error: {0}")]
TransportError(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("JSON-RPC request error: {0:?}")]
Request(#[source] jsonrpc::Error),
#[error("Subscription failed, subscribe_method: {0} unsubscribe_method: {1}")]
Subscription(String, String),
#[error("Frontend/backend channel error: {0}")]
Internal(#[source] futures::channel::mpsc::SendError),
#[error("Invalid response: {0}")]
InvalidResponse(Mismatch<String>),
#[error("The background task been terminated because: {0}; restart required")]
RestartNeeded(String),
#[error("Parse error: {0}")]
ParseError(#[source] jsonrpc::ParseError),
#[error("Invalid subscription ID")]
InvalidSubscriptionId,
#[error("Invalid request ID")]
InvalidRequestId,
#[error("A request with the same request ID has already been registered")]
DuplicateRequestId,
#[error("Method: {0} was already registered")]
MethodAlreadyRegistered(String),
#[error("Cannot use the same method name for subscribe and unsubscribe, used: {0}")]
SubscriptionNameConflict(String),
#[error("Websocket request timeout")]
WsRequestTimeout,
#[error("Configured max number of request slots exceeded")]
MaxSlotsExceeded,
#[error("Custom error: {0}")]
Custom(String),
}
#[derive(Debug, thiserror::Error)]
pub enum GenericTransportError<T: std::error::Error + Send + Sync> {
#[error("The request was too big")]
TooLarge,
#[error("Transport error: {0}")]
Inner(T),
}