opaquerr::define_kind! {
pub ErrorKind {
Protocol => "nostr protocol error",
IO => "I/O error",
Storage => "storage error",
Migration => "migration error",
Unsupported => "the operation is known but not supported",
Other => "other error",
}
}
opaquerr::define_error! {
pub Error(ErrorKind)
from {
nostr::error::Error => ErrorKind::Protocol,
std::io::Error => ErrorKind::IO,
}
}
impl Error {
pub fn storage<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::new(ErrorKind::Storage, error)
}
pub fn io<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::new(ErrorKind::IO, error)
}
pub fn migration<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::new(ErrorKind::Migration, error)
}
pub const fn unsupported(message: &'static str) -> Self {
Self::with_static_message(ErrorKind::Unsupported, message)
}
pub fn other<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
Self::new(ErrorKind::Other, error)
}
}