1opaquerr::define_kind! {
8 pub ErrorKind {
10 Protocol => "nostr protocol error",
12 IO => "I/O error",
14 Storage => "storage error",
16 Migration => "migration error",
18 Unsupported => "the operation is known but not supported",
20 Other => "other error",
22 }
23}
24
25opaquerr::define_error! {
26 pub Error(ErrorKind)
28
29 from {
30 nostr::error::Error => ErrorKind::Protocol,
31 std::io::Error => ErrorKind::IO,
32 }
33}
34
35impl Error {
36 pub fn storage<E>(error: E) -> Self
38 where
39 E: Into<Box<dyn std::error::Error + Send + Sync>>,
40 {
41 Self::new(ErrorKind::Storage, error)
42 }
43
44 pub fn io<E>(error: E) -> Self
46 where
47 E: Into<Box<dyn std::error::Error + Send + Sync>>,
48 {
49 Self::new(ErrorKind::IO, error)
50 }
51
52 pub fn migration<E>(error: E) -> Self
54 where
55 E: Into<Box<dyn std::error::Error + Send + Sync>>,
56 {
57 Self::new(ErrorKind::Migration, error)
58 }
59
60 pub const fn unsupported(message: &'static str) -> Self {
62 Self::with_static_message(ErrorKind::Unsupported, message)
63 }
64
65 pub fn other<E>(error: E) -> Self
67 where
68 E: Into<Box<dyn std::error::Error + Send + Sync>>,
69 {
70 Self::new(ErrorKind::Other, error)
71 }
72}