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
use std::time::Duration;
use thiserror::Error;
use tokio::io;
use crate::ConnectionOptions;
#[derive(Clone, Default, PartialEq, Eq, Debug)]
pub struct ConnOptions(ConnectionOptions);
impl ConnOptions {
pub(crate) fn wrap(opts: &ConnectionOptions) -> Self {
ConnOptions(opts.clone())
}
fn descr(&self) -> String {
let ConnOptions(opts) = self;
let mut msg = format!("({}:{})", opts.addr, opts.port);
if let Some(ref config_file) = opts.used_config_file {
msg += &format!(" using cjdnsadmin file at [{}]", config_file);
}
msg
}
}
#[derive(Error, Debug)]
pub enum Error {
#[error("Could not find cjdns {}, see: https://github.com/cjdelisle/cjdnsadmin#connecting", .0.descr())]
ConnectError(ConnOptions),
#[error("Could not authenticate with CJDNS {}, see: https://github.com/cjdelisle/cjdnsadmin#authentication-issues", .0.descr())]
AuthError(ConnOptions),
#[error("Error reading config file: {0}")]
ConfigFileRead(#[source] io::Error),
#[error("Bad config file: JSON parse error: {0}")]
BadConfigFile(#[source] serde_json::Error),
#[error("Address parse error: {0}")]
BadNetworkAddress(#[source] std::net::AddrParseError),
#[error("UDP error: {0}")]
NetworkOperation(#[source] io::Error),
#[error("Encoding error: {0}")]
Protocol(#[source] bencode::Error),
#[error("Remote call error: {0}")]
RemoteError(String),
#[allow(missing_docs)]
#[error("Broken txid: sent {sent_txid} but received {received_txid}")]
BrokenTx { sent_txid: String, received_txid: String },
#[error("Timeout occured: {0:?}")]
TimeOut(Duration),
}