watcher/node/src/error.rs
2025-08-29 19:09:09 +02:00

59 lines
1.3 KiB
Rust

use thiserror::Error;
use crate::log;
#[allow(dead_code)]
#[derive(Error, Debug)]
pub enum BlockchainError {
#[error("invalid account creation")]
InvalidAccountCreation,
#[error("Transactional error")]
Tx(#[from] TxError)
}
#[allow(dead_code)]
#[derive(Error, Debug)]
pub enum TxError {
#[error("from field is empty")]
FromEmpty,
#[error("to field is empty")]
ToEmpty,
#[error("insuffitient fonds")]
FromInsuffitientFonds,
#[error("0 value transaction")]
ValueEmpty,
#[error("account {0} not found in database")]
UnknownAccount(String)
}
pub fn print_error_chain(err: anyhow::Error) {
let mut err_string = String::from(format!("Error: {}\n", err));
let mut source = err.source();
let mut level = 1;
while let Some(err) = source {
err_string.push_str(format!(" {}: {}\n", level, err).as_str());
source = err.source();
level += 1;
}
log(err_string)
}
#[derive(Debug, Error)]
pub enum SystemError<T>
where
T: std::fmt::Debug
{
#[error("TODO")]
TODO,
#[error("Failed to send message: {message:?}")]
ChannelSendError { message: T },
#[error("Channel {message:?} was closed")]
ChannelClosed { message: T },
#[error("Event Bus closed")]
EventBusClosed(#[from] tokio::sync::broadcast::error::RecvError)
}