use serde::de::StdError; use std::fmt; use std::sync::PoisonError; use thiserror::Error; pub type NyxResult = Result; #[derive(Debug, Error)] pub enum NyxError { #[error("I/O error: {0}")] Io(#[from] std::io::Error), #[error("SQLite error: {0}")] Sql(#[from] rusqlite::Error), #[error("tree-sitter error: {0}")] TreeSitter(#[from] tree_sitter::LanguageError), #[error("connection-pool error: {0}")] Pool(#[from] r2d2::Error), #[error("time error: {0}")] Time(#[from] std::time::SystemTimeError), #[error("poisoned lock: {0}")] Poison(String), #[error(transparent)] Other(#[from] Box), #[error("{0}")] Msg(String), } impl From> for NyxError where T: fmt::Debug, { fn from(err: PoisonError) -> Self { NyxError::Poison(err.to_string()) } } impl From<&str> for NyxError { fn from(s: &str) -> Self { NyxError::Msg(s.to_owned()) } } impl From for NyxError { fn from(s: String) -> Self { NyxError::Msg(s) } } impl From> for NyxError { fn from(err: Box) -> Self { NyxError::Msg(err.to_string()) } }