1use std::fmt;
4
5#[derive(Debug)]
7pub enum VectorError {
8 Db(String),
10 Nostr(String),
12 Crypto(String),
14 Network(String),
16 Io(std::io::Error),
18 NotInitialized(String),
20 Other(String),
22}
23
24impl fmt::Display for VectorError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 VectorError::Db(msg) => write!(f, "Database error: {}", msg),
28 VectorError::Nostr(msg) => write!(f, "Nostr error: {}", msg),
29 VectorError::Crypto(msg) => write!(f, "Crypto error: {}", msg),
30 VectorError::Network(msg) => write!(f, "Network error: {}", msg),
31 VectorError::Io(err) => write!(f, "I/O error: {}", err),
32 VectorError::NotInitialized(msg) => write!(f, "Not initialized: {}", msg),
33 VectorError::Other(msg) => write!(f, "{}", msg),
34 }
35 }
36}
37
38impl std::error::Error for VectorError {}
39
40impl From<String> for VectorError {
41 fn from(s: String) -> Self {
42 VectorError::Other(s)
43 }
44}
45
46impl From<&str> for VectorError {
47 fn from(s: &str) -> Self {
48 VectorError::Other(s.to_string())
49 }
50}
51
52impl From<std::io::Error> for VectorError {
53 fn from(err: std::io::Error) -> Self {
54 VectorError::Io(err)
55 }
56}
57
58impl From<rusqlite::Error> for VectorError {
59 fn from(err: rusqlite::Error) -> Self {
60 VectorError::Db(err.to_string())
61 }
62}
63
64impl From<nostr_sdk::client::Error> for VectorError {
65 fn from(err: nostr_sdk::client::Error) -> Self {
66 VectorError::Nostr(err.to_string())
67 }
68}
69
70impl From<reqwest::Error> for VectorError {
71 fn from(err: reqwest::Error) -> Self {
72 VectorError::Network(err.to_string())
73 }
74}
75
76pub type Result<T> = std::result::Result<T, VectorError>;
78
79impl From<VectorError> for String {
81 fn from(err: VectorError) -> String {
82 err.to_string()
83 }
84}