nostr_types/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur in the nostr-proto crate
4#[derive(Error, Debug)]
5pub enum Error {
6    /// Assertion failed
7    #[error("Assertion failed: {0}")]
8    AssertionFailed(String),
9
10    /// Bad NIP-46 Bunker URL
11    #[error("Bad NIP-46 Bunker URL")]
12    BadBunkerUrl,
13
14    /// Bad Encrypted Message
15    #[error("Bad Encrypted Message")]
16    BadEncryptedMessage,
17
18    /// Bad Encrypted Message due to bad Base64
19    #[error("Bad Encrypted Message due to invalid base64")]
20    BadEncryptedMessageBase64(base64::DecodeError),
21
22    /// Base64 error
23    #[error("Base64 Decoding Error: {0}")]
24    Base64(#[from] base64::DecodeError),
25
26    /// Bech32 decode error
27    #[error("Bech32 Error: {0}")]
28    Bech32Decode(#[from] bech32::DecodeError),
29
30    /// Bech32 encode error
31    #[error("Bech32 Error: {0}")]
32    Bech32Encode(#[from] bech32::EncodeError),
33
34    /// Bech32 HRP error
35    #[error("Bech32 Error: {0}")]
36    Bech32Hrp(#[from] bech32::primitives::hrp::Error),
37
38    /// Crypto error
39    #[error("Crypto Error: {0}")]
40    Crypto(#[from] nip44::Error),
41
42    /// Disconnected
43    #[cfg(feature = "client")]
44    #[error("Disconnected")]
45    Disconnected,
46
47    /// Encryption/Decryption Error
48    #[error("Private Key Encryption/Decryption Error")]
49    PrivateKeyEncryption,
50
51    /// From utf8 Error
52    #[error("From UTF-8 Error")]
53    FromUtf8(#[from] std::string::FromUtf8Error),
54
55    /// Bech32 error
56    #[error("Wrong Bech32 Kind: Expected {0} found {0}")]
57    WrongBech32(String, String),
58
59    /// Key or Signature error
60    #[error("Key or Signature Error: {0}")]
61    KeyOrSignature(#[from] secp256k1::Error),
62
63    /// Event is in the future
64    #[error("Event is in the future")]
65    EventInFuture,
66
67    /// Formatting error
68    #[error("Formatting Error: {0}")]
69    Fmt(#[from] std::fmt::Error),
70
71    /// A hash mismatch verification error
72    #[error("Hash Mismatch")]
73    HashMismatch,
74
75    /// Hex string decoding error
76    #[error("Hex Decode Error: {0}")]
77    HexDecode(#[from] hex::FromHexError),
78
79    /// HTTP error
80    #[cfg(feature = "client")]
81    #[error("HTTP: {0}")]
82    Http(#[from] http::Error),
83
84    /// Invalid encrypted private key
85    #[error("Invalid Encrypted Private Key")]
86    InvalidEncryptedPrivateKey,
87
88    /// Invalid encrypted event
89    #[error("Invalid Encrypted Event")]
90    InvalidEncryptedEvent,
91
92    /// Invalid HyperLogLog data
93    #[error("Invalid HLL data")]
94    InvalidHll,
95
96    /// Invalid event Id
97    #[error("Invalid event Id")]
98    InvalidId,
99
100    /// Invalid event Id Prefix
101    #[error("Invalid event Id Prefix")]
102    InvalidIdPrefix,
103
104    /// Invalid digest length
105    #[error("Invalid digest length")]
106    InvalidLength(#[from] hmac::digest::InvalidLength),
107
108    /// Invalid NAddr
109    #[error("Invalid naddr")]
110    InvalidNAddr,
111
112    /// Invalid NEvent
113    #[error("Invalid nevent")]
114    InvalidNEvent,
115
116    /// Invalid Operation
117    #[error("Invalid Operation")]
118    InvalidOperation,
119
120    /// Invalid Private Key
121    #[error("Invalid Private Key")]
122    InvalidPrivateKey,
123
124    /// Invalid Profile
125    #[error("Invalid Profile")]
126    InvalidProfile,
127
128    /// Invalid public key
129    #[error("Invalid Public Key")]
130    InvalidPublicKey,
131
132    /// Invalid public key prefix
133    #[error("Invalid Public Key Prefix")]
134    InvalidPublicKeyPrefix,
135
136    /// Invalid recipient
137    #[error("Invalid Recipient")]
138    InvalidRecipient,
139
140    /// Invalid state
141    #[error("Invalid state: \"{0}\"")]
142    InvalidState(String),
143
144    /// Invalid URL
145    #[error("Invalid URL: \"{0}\"")]
146    InvalidUrl(#[from] url::ParseError),
147
148    /// Invalid URI
149    #[cfg(feature = "client")]
150    #[error("Invalid URI: {0}")]
151    InvalidUri(#[from] http::uri::InvalidUri),
152
153    /// Invalid URL TLV encoding
154    #[error("Invalid URL TLV encoding")]
155    InvalidUrlTlv,
156
157    /// Invalid URL Host
158    #[error("Invalid URL Host: \"{0}\"")]
159    InvalidUrlHost(String),
160
161    /// Invalid URL Scheme
162    #[error("Invalid URL Scheme: \"{0}\"")]
163    InvalidUrlScheme(String),
164
165    /// Missing URL Authority
166    #[error("Missing URL Authority")]
167    InvalidUrlMissingAuthority,
168
169    /// NIP-46 error
170    #[cfg(feature = "nip46")]
171    #[error("NIP-46 error: {0}")]
172    Nip46Error(String),
173
174    /// NIP-46 failed to post
175    #[cfg(feature = "nip46")]
176    #[error("NIP-46 failed to post: {0}")]
177    Nip46FailedToPost(String),
178
179    /// NIP-46 failed to post
180    #[cfg(feature = "nip46")]
181    #[error("NIP-46 no response")]
182    Nip46NoResponse,
183
184    /// Addr to a non-replaceable event kind
185    #[error("Event kind is not replaceable")]
186    NonReplaceableAddr,
187
188    /// No Private Key
189    #[error("No private key")]
190    NoPrivateKey,
191
192    /// No Public Key
193    #[error("No public key")]
194    NoPublicKey,
195
196    /// Out of Range
197    #[error("Out of Range")]
198    OutOfRange(usize),
199
200    /// Parse integer error
201    #[error("Parse integer error")]
202    ParseInt(#[from] std::num::ParseIntError),
203
204    /// Relay did not AUTH
205    #[error("Relay (broken) says auth-required before challenging with AUTH")]
206    RelayDidNotAuth,
207
208    /// Relay forgot that we successfully AUTHed
209    #[error("Relay (broken) forgot that we already successfully AUTHed")]
210    RelayForgotAuth,
211
212    /// Relay rejected our post
213    #[error("Relay rejected our post")]
214    RelayRejectedPost,
215
216    /// Relay rejected our AUTH
217    #[error("Relay rejected our AUTH")]
218    RelayRejectedAuth,
219
220    /// Relay requires AUTH but we aren't supplying it
221    #[error("Relay requires AUTH")]
222    RelayRequiresAuth,
223
224    /// HTTP request eror
225    #[cfg(feature = "client")]
226    #[error("HTTP error: {0}")]
227    Reqwest(#[from] reqwest::Error),
228
229    /// Scrypt error
230    #[error("Scrypt invalid output length")]
231    Scrypt,
232
233    /// Serialization error
234    #[error("JSON (de)serialization error: {0}")]
235    SerdeJson(#[from] serde_json::Error),
236
237    /// Signer is locked
238    #[error("Signer is locked")]
239    SignerIsLocked,
240
241    /// Try from slice error
242    #[error("Try From Slice error: {0}")]
243    Slice(#[from] std::array::TryFromSliceError),
244
245    /// Speedy error
246    #[cfg(feature = "speedy")]
247    #[error("Speedy (de)serialization error: {0}")]
248    Speedy(#[from] speedy::Error),
249
250    /// Tag mismatch
251    #[error("Tag mismatch")]
252    TagMismatch,
253
254    /// Timeout
255    #[cfg(feature = "client")]
256    #[error("Timeout")]
257    TimedOut,
258
259    /// Timeout
260    #[cfg(feature = "client")]
261    #[error("Timeout: {0}")]
262    Timeout(#[from] tokio::time::error::Elapsed),
263
264    /// Unknown event kind
265    #[error("Unknown event kind = {0}")]
266    UnknownEventKind(u32),
267
268    /// Unknown Key Security
269    #[error("Unknown key security = {0}")]
270    UnknownKeySecurity(u8),
271
272    /// Unknown Cipher Version
273    #[error("Unknown cipher version = {0}")]
274    UnknownCipherVersion(u8),
275
276    /// Unpad error
277    #[error("Decryption error: {0}")]
278    Unpad(#[from] aes::cipher::block_padding::UnpadError),
279
280    /// Unsupported Algorithm
281    #[error("Unsupported algorithm")]
282    UnsupportedAlgorithm,
283
284    /// Url Error
285    #[error("Not a valid nostr relay url: {0}")]
286    Url(String),
287
288    /// UTF-8 error
289    #[error("UTF-8 Error: {0}")]
290    Utf8Error(#[from] std::str::Utf8Error),
291
292    /// Websocket error
293    #[cfg(feature = "client")]
294    #[error("Websocket error: {0}")]
295    Websocket(#[from] tungstenite::Error),
296
297    /// Websocket Connection Failed
298    #[cfg(feature = "client")]
299    #[error("Websocket connection failed: {0}")]
300    WebsocketConnectionFailed(http::StatusCode),
301
302    /// Wrong event kind
303    #[error("Wrong event kind")]
304    WrongEventKind,
305
306    /// Wrong length hex string
307    #[error("Wrong length hex string")]
308    WrongLengthHexString,
309
310    /// Wrong length bytes for event kind
311    #[error("Wrong length bytes for event kind")]
312    WrongLengthKindBytes,
313
314    /// Wrong Decryption Password
315    #[error("Wrong decryption password")]
316    WrongDecryptionPassword,
317
318    /// Zap Receipt issue
319    #[error("Invalid Zap Receipt: {0}")]
320    ZapReceipt(String),
321}