1#[derive(Debug, thiserror::Error)]
4pub enum NetError {
5 #[error("invalid {what}: {msg}")]
7 Invalid { what: &'static str, msg: String },
8 #[error("crypto: {0}")]
10 Crypto(String),
11 #[error("network: {0}")]
13 Network(String),
14 #[error(transparent)]
16 Keys(#[from] weirdnet_keys::KeysError),
17 #[error(transparent)]
18 Json(#[from] serde_json::Error),
19 #[error("{0}")]
21 Other(String),
22}
23
24impl NetError {
25 pub fn invalid(what: &'static str, msg: impl Into<String>) -> Self {
26 NetError::Invalid { what, msg: msg.into() }
27 }
28 pub(crate) fn net(e: impl std::fmt::Display) -> Self {
29 NetError::Network(e.to_string())
30 }
31}
32
33pub type Result<T> = std::result::Result<T, NetError>;