Skip to main content

tauri_plugin_nostr_sync/
error.rs

1use serde::{ser::Serializer, Serialize};
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, thiserror::Error)]
6pub enum Error {
7    #[error(transparent)]
8    Io(#[from] std::io::Error),
9
10    #[error(transparent)]
11    Nostr(#[from] nostr_sdk::client::Error),
12
13    #[error("signer not set — call set_signer before publishing or fetching")]
14    SignerNotSet,
15
16    #[error("payload too large: {size} bytes exceeds {limit} byte limit")]
17    PayloadTooLarge { size: usize, limit: usize },
18
19    #[error("encryption failed: {0}")]
20    EncryptionFailed(String),
21
22    #[error("signing failed: {0}")]
23    SigningFailed(String),
24
25    #[error("decryption failed: {0}")]
26    DecryptionFailed(String),
27
28    #[error("invalid namespace '{0}': must be non-empty and contain no '/' characters")]
29    InvalidNamespace(String),
30
31    #[error("invalid category '{0}': must be non-empty and contain no '/' characters")]
32    InvalidCategory(String),
33
34    #[error("no relays accepted the event")]
35    NoRelaysAccepted,
36
37    #[error("payload limit {requested} bytes exceeds the {max} byte maximum")]
38    InvalidPayloadLimit { requested: usize, max: usize },
39
40    #[cfg(mobile)]
41    #[error(transparent)]
42    PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
43}
44
45impl Serialize for Error {
46    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
47    where
48        S: Serializer,
49    {
50        serializer.serialize_str(self.to_string().as_ref())
51    }
52}