use std::fmt::Debug;
use crate::impl_sourceless_error;
#[derive(Debug)]
pub enum NodeError {
NoReachablePeers,
}
impl core::fmt::Display for NodeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NodeError::NoReachablePeers => {
write!(f, "the node has exhausted all possible options for peers")
}
}
}
}
impl_sourceless_error!(NodeError);
#[derive(Debug)]
pub enum ClientError {
SendError,
RecvError,
}
impl core::fmt::Display for ClientError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ClientError::SendError => {
write!(f, "the receiver of this message was dropped from memory.")
}
ClientError::RecvError => {
write!(f, "the sender of data was dropped from memory.")
}
}
}
}
impl_sourceless_error!(ClientError);
#[derive(Debug)]
pub enum FetchBlockError {
SendError,
RecvError,
UnknownHash,
}
impl core::fmt::Display for FetchBlockError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FetchBlockError::SendError => {
write!(f, "the receiver of this message was dropped from memory.")
}
FetchBlockError::RecvError => write!(
f,
"the channel to the client was likely closed by the node and dropped from memory."
),
FetchBlockError::UnknownHash => {
write!(f, "the hash is not a member of the chain of most work.")
}
}
}
}
impl_sourceless_error!(FetchBlockError);
#[derive(Debug)]
pub enum PackageError {
InvalidPackageLength(usize),
UnrelatedTransactions,
}
impl core::fmt::Display for PackageError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PackageError::InvalidPackageLength(s) => {
write!(
f,
"package must include at most two transactions, got {}",
s
)
}
PackageError::UnrelatedTransactions => {
write!(f, "packages must have dependent inputs and outputs.")
}
}
}
}