dsf_core/
error.rs

1#[cfg(feature = "std")]
2use std::io::Error as IoError;
3#[cfg(feature = "std")]
4use std::time::SystemTimeError;
5
6use crate::base::BaseError;
7use crate::options::OptionsError;
8
9#[derive(PartialEq, Debug, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
11pub enum Error {
12    IO,
13    Time,
14    InvalidOption,
15    InvalidOptionLength,
16    InvalidPageLength,
17    InvalidPageKind,
18    InvalidMessageKind,
19    CryptoError,
20    UnexpectedPageType,
21    UnexpectedServiceId,
22    UnexpectedApplicationId,
23    InvalidServiceVersion,
24    NoPrivateKey,
25    NoPublicKey,
26    NoSignature,
27    ExpectedPrimaryPage,
28    ExpectedSecondaryPage,
29    ExpectedDataObject,
30    UnexpectedPeerId,
31    NoPeerId,
32    KeyIdMismatch,
33    PublicKeyChanged,
34    Unimplemented,
35    SendError,
36    NoRequestId,
37    InvalidMessageType,
38    InvalidJson,
39    NoPeersFound,
40    NotFound,
41    InvalidResponse,
42    UnknownService,
43    InvalidSignature,
44    UnexpectedPageKind,
45    NoReplicasFound,
46    UnknownPeer,
47    NoSecretKey,
48    SecretKeyMismatch,
49    Base(BaseError),
50    Options(OptionsError),
51    Timeout,
52    Unknown,
53}
54
55#[cfg(feature = "std")]
56impl From<IoError> for Error {
57    fn from(e: IoError) -> Error {
58        error!("io error: {}", e);
59        Error::IO
60    }
61}
62
63#[cfg(feature = "std")]
64impl From<SystemTimeError> for Error {
65    fn from(_e: SystemTimeError) -> Error {
66        Error::Time
67    }
68}
69
70impl From<BaseError> for Error {
71    fn from(e: BaseError) -> Error {
72        Error::Base(e)
73    }
74}
75
76impl From<OptionsError> for Error {
77    fn from(e: OptionsError) -> Error {
78        Error::Options(e)
79    }
80}