Skip to main content

nethsm/cli/
error.rs

1//! Error handling for the `nethsm` CLI.
2
3use std::path::PathBuf;
4
5use chrono::{DateTime, Utc};
6
7use crate::SystemState;
8
9/// The error that may occur when using the "nethsm" command line interface.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// A config error
13    #[error("Configuration issue: {0}")]
14    Config(#[from] crate::cli::config::Error),
15
16    /// The NetHSM is locked
17    #[error("The NetHsm is locked")]
18    Locked,
19
20    /// The NetHSM is failed
21    #[error("The NetHSM is failed")]
22    Failed,
23
24    /// The NetHSM is failed
25    #[error("The NetHSM system state is unknown: {system_state:?}")]
26    UnknownSystemState {
27        /// The unknown system state.
28        system_state: SystemState,
29    },
30
31    /// An I/O error
32    #[error("I/O error: {0}")]
33    Io(#[from] std::io::Error),
34
35    /// Unable to open output file
36    #[error("Failed to open output file: {0}")]
37    OutputFileOpen(PathBuf),
38
39    /// Unable to open output file
40    #[error("The output file exists already: {0}")]
41    OutputFileExists(PathBuf),
42
43    /// Error processing backup file
44    #[error("Backup file is corrupted: {0}")]
45    Backup(#[from] crate::backup::Error),
46
47    /// Request deserialization error
48    #[error("Request deserialization failed: {0}")]
49    Request(#[from] Box<signstar_request_signature::Error>),
50
51    /// Processing a signing request failed.
52    #[error("Signing request processing error: {0}")]
53    SigningRequest(String),
54
55    /// Given time cannot be represented in OpenPGP.
56    #[error("Given time cannot be represented in OpenPGP: {0}")]
57    InvalidTime(DateTime<Utc>),
58
59    /// An option is missing
60    #[error(
61        "The \"{0}\" option must be provided for this command if more than one environment is defined."
62    )]
63    OptionMissing(String),
64}