Skip to content

Commit

Permalink
pool: remove thiserror dep
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 6, 2024
1 parent 79ef2b5 commit 1304b45
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 103 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* lmdb: remove `thiserror` and `tracing` deps ([Yuki Kishimoto])
* indexeddb: remove `thiserror` and `tracing` deps ([Yuki Kishimoto])
* zapper: remove `thiserror` dep ([Yuki Kishimoto])
* pool: remove `tokio-stream` dep ([Yuki Kishimoto])
* pool: remove `thiserror` and `tokio-stream` deps ([Yuki Kishimoto])
* nwc: remove `thiserror` dep and unnecessary `Error::Zapper` variant ([Yuki Kishimoto])
* ffi: drop support for `i686-linux-android` target ([Yuki Kishimoto])
* ffi: remove `MockRelay` ([Yuki Kishimoto])
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/nostr-relay-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ negentropy = { workspace = true, features = ["std"] }
negentropy-deprecated = { workspace = true, features = ["std"] }
nostr = { workspace = true, features = ["std"] }
nostr-database.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["macros", "sync"] }
tracing.workspace = true

Expand Down
92 changes: 58 additions & 34 deletions crates/nostr-relay-pool/src/pool/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,87 @@
// Copyright (c) 2023-2024 Rust Nostr Developers
// Distributed under the MIT software license

use core::convert::Infallible;
use std::convert::Infallible;
use std::fmt;

use nostr::types::url;
use nostr_database::DatabaseError;
use thiserror::Error;

use crate::relay;

/// Relay Pool error
#[derive(Debug, Error)]
#[derive(Debug)]
pub enum Error {
/// Url parse error
#[error("impossible to parse relay URL: {0}")]
RelayUrl(#[from] url::Error),
RelayUrl(url::Error),
/// Relay error
#[error(transparent)]
Relay(#[from] relay::Error),
Relay(relay::Error),
/// Database error
#[error(transparent)]
Database(#[from] DatabaseError),
/// No relays
#[error("too many relays (limit: {limit})")]
Database(DatabaseError),
/// Infallible
Infallible(Infallible),
/// Notification Handler error
Handler(String),
/// Too many relays
TooManyRelays {
/// Max numer allowed
limit: usize,
},
/// No relays
#[error("no relays")]
NoRelays,
/// No relays specified
#[error("no relays specified")]
NoRelaysSpecified,
/// Msg not sent
#[error("message not sent")]
MsgNotSent,
/// Msgs not sent
#[error("messages not sent")]
MsgsNotSent,
/// Event/s not published
#[error("event/s not published")]
EventNotPublished,
/// Not subscribed
#[error("not subscribed")]
NotSubscribed,
/// Failed
Failed,
/// Negentropy reconciliation failed
#[error("negentropy reconciliation failed")]
NegentropyReconciliationFailed,
/// Relay not found
#[error("relay not found")]
RelayNotFound,
/// Relay Pool is shutdown
#[error("Relay Pool is shutdown")]
Shutdown,
/// Notification Handler error
#[error("notification handler error: {0}")]
Handler(String),
/// Infallible
#[error(transparent)]
Infallible(#[from] Infallible),
}

impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::RelayUrl(e) => write!(f, "{e}"),
Self::Relay(e) => write!(f, "{e}"),
Self::Database(e) => write!(f, "{e}"),
Self::Infallible(e) => write!(f, "{e}"),
Self::Handler(e) => write!(f, "{e}"),
Self::TooManyRelays { limit } => write!(f, "too many relays (limit: {limit})"),
Self::NoRelays => write!(f, "no relays"),
Self::NoRelaysSpecified => write!(f, "no relays specified"),
Self::Failed => write!(f, "completed without success"), // TODO: better error?
Self::NegentropyReconciliationFailed => write!(f, "negentropy reconciliation failed"),
Self::RelayNotFound => write!(f, "relay not found"),
Self::Shutdown => write!(f, "relay pool is shutdown"),
}
}
}

impl From<url::Error> for Error {
fn from(e: url::Error) -> Self {
Self::RelayUrl(e)
}
}

impl From<relay::Error> for Error {
fn from(e: relay::Error) -> Self {
Self::Relay(e)
}
}

impl From<DatabaseError> for Error {
fn from(e: DatabaseError) -> Self {
Self::Database(e)
}
}

impl From<Infallible> for Error {
fn from(e: Infallible) -> Self {
Self::Infallible(e)
}
}
6 changes: 3 additions & 3 deletions crates/nostr-relay-pool/src/pool/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl InnerRelayPool {
}

if output.success.is_empty() {
return Err(Error::MsgNotSent);
return Err(Error::Failed);
}

Ok(output)
Expand Down Expand Up @@ -469,7 +469,7 @@ impl InnerRelayPool {
}

if output.success.is_empty() {
return Err(Error::EventNotPublished);
return Err(Error::Failed);
}

Ok(output)
Expand Down Expand Up @@ -611,7 +611,7 @@ impl InnerRelayPool {
}

if output.success.is_empty() {
return Err(Error::NotSubscribed);
return Err(Error::Failed);
}

Ok(output)
Expand Down
Loading

0 comments on commit 1304b45

Please sign in to comment.