Skip to main content

pass_it_on/
error.rs

1use thiserror::Error;
2use thiserror_ext::{Box, Construct};
3
4/// Errors returned by pass-it-on library.
5#[derive(Error, Debug, Box, Construct)]
6#[thiserror_ext(newtype(name = Error))]
7pub enum ErrorKind {
8    /// At least one [`Endpoint`][`crate::endpoints::Endpoint`] needs to be defined for a server.
9    #[error("At least one endpoint must be defined")]
10    MissingEndpoint,
11
12    /// At least one [`Interface`][`crate::interfaces::Interface`] needs to be defined for a server or client.
13    #[error("At least one interface must be defined")]
14    MissingInterface,
15
16    /// Validation failed for an [`InterfaceConfig`][`crate::interfaces::InterfaceConfig`].
17    #[error("Invalid Interface Configuration: {0}")]
18    InvalidInterfaceConfiguration(String),
19
20    /// Validation failed for an [`EndpointConfig`][`crate::endpoints::EndpointConfig`].
21    #[error("Invalid Endpoint Configuration: {0}")]
22    InvalidEndpointConfiguration(String),
23
24    /// matrix room name does not appear to be a room.
25    #[error("Room identifiers must start with # or !")]
26    InvalidMatrixRoomIdentifier,
27
28    /// Port needs to be in a valid u16 range.
29    #[error("Invalid port number, valid u16 value expected and got {0}")]
30    InvalidPortNumber(i64),
31
32    /// Call to an interface feature that is not enabled.
33    #[error("Interface feature {0} is not enabled")]
34    DisabledInterfaceFeature(String),
35
36    /// Return when an endpoint feature is called but not enabled
37    #[error("Endpoint feature {0} is not enabled")]
38    DisabledEndpointFeature(String),
39
40    // ### Converting from other error types ###
41    /// Pass-thru [`std::io::Error`].
42    #[error("std::io Error: {0}")]
43    IOError(#[from] std::io::Error),
44
45    /// Pass-thru `serde_json::Error`.
46    #[error("Serde_json Error: {0}")]
47    SerdeJsonError(#[from] serde_json::Error),
48
49    #[cfg(feature = "parse-cfg")]
50    /// Pass-thru `toml::de::Error`.
51    #[error("Serde Toml Error: {0}")]
52    SerdeTomlError(#[from] toml::de::Error),
53
54    #[cfg(feature = "matrix")]
55    /// Pass-thru `matrix_sdk::Error`.
56    #[error("Matrix_SDK Error: {0}")]
57    MatrixSDKError(#[from] matrix_sdk::Error),
58
59    #[cfg(feature = "matrix")]
60    /// Pass-thru `matrix_sdk::ClientBuildError`.
61    #[error("Matrix ClientBuild Error: {0}")]
62    MatrixClientBuildError(#[from] matrix_sdk::ClientBuildError),
63
64    #[cfg(feature = "matrix")]
65    /// Pass-thru `matrix_sdk::encryption::secret_storage::SecretStorageError`.
66    #[error("Matrix SecretStorage Error: {0}")]
67    MatrixSecretStoreError(#[from] matrix_sdk::encryption::secret_storage::SecretStorageError),
68
69    #[cfg(feature = "matrix")]
70    /// Pass-thru `matrix_sdk::encryption::recovery::RecoveryError`.
71    #[error("Matrix RecoveryError Error: {0}")]
72    MatrixRecoveryError(#[from] matrix_sdk::encryption::recovery::RecoveryError),
73
74    #[cfg(all(unix, any(feature = "pipe-client", feature = "pipe-server", feature = "pipe")))]
75    /// Pass-thru `nix::errno::Errno`.
76    #[error("Nix ErrorNo Error: {0}")]
77    NixErrorNoError(#[from] nix::errno::Errno),
78
79    #[cfg(any(feature = "http-client", feature = "http-server"))]
80    /// Pass-thru `url::ParseError`.
81    #[error("Url Parse Error: {0}")]
82    UrlParseError(#[from] url::ParseError),
83
84    #[cfg(feature = "email")]
85    /// Pass-thru `mail_send::Error`.
86    #[error("Mail Send Error: {0}")]
87    MailSendError(#[from] mail_send::Error),
88}