Skip to main content

weirdnet_sync/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4#[non_exhaustive]
5pub enum SyncError {
6    #[error("{0}")]
7    Crypto(String),
8    #[error("refused: {0}")]
9    Refused(String),
10    #[error("codec: {0}")]
11    Codec(String),
12    #[error("{0}")]
13    Protocol(String),
14    /// Reading or writing an [`crate::identity::Identity`]'s files.
15    #[error("{0}")]
16    Io(String),
17    /// An [`crate::identity::Identity`] that can't be created, adopted or opened as asked.
18    #[error("{0}")]
19    Identity(String),
20    /// Something only a device holding the identity seed may do (admit, revoke, grant,
21    /// rotate), asked of a service device linked without it.
22    #[error("not permitted on a service device: {0}")]
23    NotPermitted(String),
24}
25
26impl From<weirdnet_keys::KeysError> for SyncError {
27    fn from(e: weirdnet_keys::KeysError) -> Self {
28        SyncError::Crypto(e.to_string())
29    }
30}
31
32impl From<weirdnet_net::NetError> for SyncError {
33    fn from(e: weirdnet_net::NetError) -> Self {
34        SyncError::Crypto(e.to_string())
35    }
36}
37
38pub type Result<T> = std::result::Result<T, SyncError>;