encrypt_config/
error.rs

1//! The error types of `encrypt config`.
2
3use snafu::Snafu;
4
5/// The Error types of `encrypt config`, which is implemented by [`snafu`].
6#[derive(Snafu, Debug)]
7#[snafu(visibility(pub(crate)), context(suffix(false)))]
8pub enum ConfigError {
9    /// This error will be returned when the value cannot seriliazed or deserialized.
10    #[snafu(
11        display("Serde Error. Cannot seriliaze or deseriliaze."),
12        context(false)
13    )]
14    SerdeError {
15        /// The error returned by `serde_json`.
16        source: serde_json::Error,
17    },
18    #[cfg(feature = "secret")]
19    /// This error will be returned when the encrypter cannot be deserialized from keyring password. This may caused by the private key stored in keyring being incorrect, modified or recreated.
20    #[snafu(display("Failed to deseriliaze encrypter from keyring."))]
21    LoadEncrypterFailed,
22    #[cfg(feature = "secret")]
23    /// This error will be returned when the OS' secret manager cannot be accessed.
24    #[snafu(
25        display(
26            "Keyring Error.\nThis error may caused by OS' secret manager, the rsa private key cannot be saved or read."
27        ),
28    )]
29    KeyringError,
30    /// This error will be returned when the encryption or decryption failed.
31    #[snafu(
32        display("Encryption Error. Cannot encrypt or decrypt.\nIf it's a decrypt error, maybe it's the private key stored in keyring being incorrect, modified or recreated."),
33        context(false)
34    )]
35    #[cfg(feature = "secret")]
36    EncryptionError {
37        /// The error returned by `rsa`.
38        source: rsa::Error,
39    },
40    /// This error will be returned when the config cannot be saved to or read from the file.
41    #[snafu(display("IO error. Cannot operate the file."), context(false))]
42    IoError {
43        /// The error returned by `std::io`.
44        source: std::io::Error,
45    },
46}
47
48/// The Result type of `encrypt config`, which is implemented by [`snafu`].
49pub type ConfigResult<T> = Result<T, ConfigError>;