diff --git a/Cargo.lock b/Cargo.lock index ec50dc3..742b912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,7 @@ dependencies = [ "rustls-pki-types", "secp256k1 0.29.0", "serde", + "serde_json", "speedy", "tempfile", "textnonce", diff --git a/Cargo.toml b/Cargo.toml index fd33311..684cc67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ rustls-pki-types= "1.3" rustls-pemfile = "2.1" secp256k1 = { version = "0.29", features = [ "hashes", "global-context", "rand-std" ] } serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" speedy = "0.8" textnonce = "1" tokio = { version = "1", features = [ "full" ] } diff --git a/src/error.rs b/src/error.rs index fe57d6b..44ee231 100644 --- a/src/error.rs +++ b/src/error.rs @@ -97,6 +97,9 @@ pub enum ChorusError { // Filter is underspecified Scraper, + // Serde JSON + SerdeJson(serde_json::Error), + // Speedy Speedy(speedy::Error), @@ -144,6 +147,7 @@ impl std::fmt::Display for ChorusError { ChorusError::TimedOut => write!(f, "Timed out"), ChorusError::Tungstenite(e) => write!(f, "{e}"), ChorusError::Scraper => write!(f, "Filter is underspecified. Scrapers are not allowed"), + ChorusError::SerdeJson(e) => write!(f, "{e}"), ChorusError::Speedy(e) => write!(f, "{e}"), ChorusError::TooManySubscriptions => write!(f, "Too many subscriptions"), ChorusError::UrlParse(e) => write!(f, "{e}"), @@ -206,6 +210,7 @@ impl ChorusError { ChorusError::TimedOut => 0.1, ChorusError::Tungstenite(_) => 0.0, ChorusError::Scraper => 0.4, + ChorusError::SerdeJson(_) => 0.0, ChorusError::Speedy(_) => 0.0, ChorusError::TooManySubscriptions => 0.1, ChorusError::UrlParse(_) => 0.1, @@ -392,3 +397,13 @@ impl From for Error { } } } + +impl From for Error { + #[track_caller] + fn from(err: serde_json::Error) -> Self { + Error { + inner: ChorusError::SerdeJson(err), + location: std::panic::Location::caller(), + } + } +}