signstar_yubihsm2/error.rs
1//! Error handling.
2
3use std::path::PathBuf;
4
5/// The error that may occur when using a YubiHSM2 device.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8 /// A client operation failed.
9 #[error("YubiHSM client operation failed while {context}:\n{source}")]
10 Client {
11 /// The context in which the error occurred.
12 ///
13 /// This is meant to complete the sentence "YubiHSM client operation failed while ".
14 context: &'static str,
15
16 /// The source error.
17 source: yubihsm::client::Error,
18 },
19
20 /// A device operation failed.
21 #[error("YubiHSM device operation failed while {context}:\n{source}")]
22 Device {
23 /// The context in which the error occurred.
24 ///
25 /// This is meant to complete the sentence "YubiHSM device operation failed while ".
26 context: &'static str,
27
28 /// The source error.
29 source: yubihsm::device::Error,
30 },
31
32 /// A device operation failed.
33 #[error("Certificate generation failed while {context}:\n{source}")]
34 CertificateGeneration {
35 /// The context in which the error occurred.
36 ///
37 /// This is meant to complete the sentence "Certificate generation failed while ".
38 context: &'static str,
39
40 /// The source error.
41 source: signstar_crypto::signer::error::Error,
42 },
43
44 /// An I/O error occurred for a file.
45 #[error("I/O error for file {path} while {context}: {source}")]
46 IoPath {
47 /// The path to the file for which the error occurred.
48 path: PathBuf,
49 /// The context in which the error occurs.
50 ///
51 /// This is meant to complete the sentence "I/O error for file {path} while ".
52 context: &'static str,
53 /// The error source.
54 source: std::io::Error,
55 },
56
57 /// An I/O error occurred for a file.
58 #[error("JSON serialization error while {context}: {source}")]
59 Json {
60 /// The context in which the error occurs.
61 ///
62 /// This is meant to complete the sentence "JSON serialization error while ".
63 context: &'static str,
64 /// The error source.
65 source: serde_json::Error,
66 },
67
68 /// An I/O error occurred for a file.
69 #[error("Deserialization of the wrap file failed while {context}: {source}")]
70 InvalidWrap {
71 /// The context in which the error occurs.
72 ///
73 /// This is meant to complete the sentence "Deserialization of the wrap file failed while
74 /// ".
75 context: &'static str,
76 /// The error source.
77 source: yubihsm::wrap::Error,
78 },
79
80 /// A generic I/O error occurred.
81 #[error("I/O error occurred while {context}: {source}")]
82 Io {
83 /// The context in which the error occurs.
84 ///
85 /// This is meant to complete the sentence "I/O error occurred while ".
86 context: &'static str,
87 /// The error source.
88 source: std::io::Error,
89 },
90}