depend on serde_json

This commit is contained in:
Mike Dilger 2024-06-26 12:02:00 +12:00
parent 577243789e
commit bc44aafd2d
3 changed files with 17 additions and 0 deletions

1
Cargo.lock generated
View File

@ -260,6 +260,7 @@ dependencies = [
"rustls-pki-types",
"secp256k1 0.29.0",
"serde",
"serde_json",
"speedy",
"tempfile",
"textnonce",

View File

@ -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" ] }

View File

@ -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<speedy::Error> for Error {
}
}
}
impl From<serde_json::Error> for Error {
#[track_caller]
fn from(err: serde_json::Error) -> Self {
Error {
inner: ChorusError::SerdeJson(err),
location: std::panic::Location::caller(),
}
}
}