Skip to main content

signstar_client/
error.rs

1//! Error handling.
2
3use std::path::PathBuf;
4
5use crate::ssh::client::ConnectConfig;
6
7/// Signature request processing error.
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    /// No configuration files present.
11    #[error("No configuration files present in any of the default paths:\n {paths}", paths = ConnectConfig::CONFIG_ORDER.iter().map(|path| format!("- {path}")).collect::<Vec<_>>().join("\n"))]
12    ConfigMissing,
13
14    /// An I/O error occurred.
15    #[error("I/O error while {context}: {source}")]
16    Io {
17        /// The context in which the error occurred.
18        ///
19        /// This is meant to complete the sentence "I/O error at path {path} while ".
20        context: String,
21
22        /// The error source.
23        source: std::io::Error,
24    },
25
26    /// An I/O error occurred at a specific path.
27    #[error("I/O error at path {path} while {context}: {source}")]
28    IoPath {
29        /// The path where the I/O error occurred.
30        path: PathBuf,
31
32        /// The context in which the error occurred.
33        ///
34        /// This is meant to complete the sentence "I/O error at path {path} while ".
35        context: String,
36
37        /// The error source.
38        source: std::io::Error,
39    },
40
41    /// Requesting signing via SSH failed.
42    #[error("SSH client error: {0}")]
43    SshClient(#[from] crate::ssh::client::Error),
44
45    /// A signstar-common error occurred.
46    #[error("Signstar-common error: {0}")]
47    SignstarCommon(#[from] signstar_common::Error),
48
49    /// TOML deserialization error.
50    #[error("TOML deserialization error: {0}")]
51    Toml(#[from] toml::de::Error),
52
53    /// A garde validation error occurred.
54    #[error("Validation error while {context}: {source}")]
55    Validation {
56        /// The context in which the error occurred.
57        ///
58        /// This is meant to complete the sentence "Validation error while ".
59        context: String,
60
61        /// The error source.
62        source: garde::Report,
63    },
64}