Error type

This commit is contained in:
Mike Dilger 2022-12-20 18:35:00 +13:00
parent 3988efce54
commit 52a94eb32c
2 changed files with 48 additions and 0 deletions

47
src/error.rs Normal file
View File

@ -0,0 +1,47 @@
use crate::comms::BusMessage;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Error broadcasting: {0}")]
BroadcastSend(#[from] tokio::sync::broadcast::error::SendError<BusMessage>),
#[error("Error receiving broadcast: {0}")]
BroadcastReceive(#[from] tokio::sync::broadcast::error::RecvError),
#[error("Error: {0}")]
General(String),
#[error("Task join error: {0}")]
JoinError(#[from] tokio::task::JoinError),
#[error("Error sending mpsc: {0}")]
MpscSend(#[from] tokio::sync::mpsc::error::SendError<BusMessage>),
#[error("Nostr: {0}")]
Nostr(#[from] nostr_proto::Error),
#[error("I/O Error: {0}")]
Io(#[from] std::io::Error),
#[error("Bad integer: {0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("SerdeJson Error: {0}")]
SerdeJson(#[from] serde_json::Error),
#[error("SQL: {0}")]
Sql(#[from] rusqlite::Error),
}
impl From<String> for Error {
fn from(s: String) -> Error {
Error::General(s)
}
}
impl From<&str> for Error {
fn from(s: &str) -> Error {
Error::General(s.to_string())
}
}

View File

@ -1,4 +1,5 @@
mod comms;
mod error;
fn main() {
tracing_subscriber::fmt::init();