sentinel_proxy/acme/
error.rs

1//! ACME error types
2
3use std::io;
4use thiserror::Error;
5
6/// Errors that can occur during ACME operations
7#[derive(Debug, Error)]
8pub enum AcmeError {
9    /// No ACME account has been initialized
10    #[error("ACME account not initialized - call init_account() first")]
11    NoAccount,
12
13    /// Failed to create or load ACME account
14    #[error("Failed to create ACME account: {0}")]
15    AccountCreation(String),
16
17    /// Failed to create certificate order
18    #[error("Failed to create certificate order: {0}")]
19    OrderCreation(String),
20
21    /// Challenge validation failed
22    #[error("Challenge validation failed for domain '{domain}': {message}")]
23    ChallengeValidation { domain: String, message: String },
24
25    /// Certificate finalization failed
26    #[error("Failed to finalize certificate: {0}")]
27    Finalization(String),
28
29    /// Storage operation failed
30    #[error("Storage error: {0}")]
31    Storage(#[from] StorageError),
32
33    /// ACME protocol error from instant-acme
34    #[error("ACME protocol error: {0}")]
35    Protocol(String),
36
37    /// Operation timed out
38    #[error("Operation timed out: {0}")]
39    Timeout(String),
40
41    /// No HTTP-01 challenge available for domain
42    #[error("No HTTP-01 challenge available for domain '{0}'")]
43    NoHttp01Challenge(String),
44
45    /// Certificate parsing error
46    #[error("Failed to parse certificate: {0}")]
47    CertificateParse(String),
48}
49
50/// Errors specific to certificate storage operations
51#[derive(Debug, Error)]
52pub enum StorageError {
53    /// IO error during file operations
54    #[error("IO error: {0}")]
55    Io(#[from] io::Error),
56
57    /// Failed to serialize/deserialize data
58    #[error("Serialization error: {0}")]
59    Serialization(String),
60
61    /// Storage directory not writable
62    #[error("Storage directory not writable: {path}")]
63    NotWritable { path: String },
64
65    /// Certificate not found
66    #[error("Certificate not found for domain: {domain}")]
67    CertificateNotFound { domain: String },
68
69    /// Invalid storage structure
70    #[error("Invalid storage structure: {0}")]
71    InvalidStructure(String),
72}
73
74impl From<serde_json::Error> for StorageError {
75    fn from(e: serde_json::Error) -> Self {
76        StorageError::Serialization(e.to_string())
77    }
78}
79
80impl From<instant_acme::Error> for AcmeError {
81    fn from(e: instant_acme::Error) -> Self {
82        AcmeError::Protocol(e.to_string())
83    }
84}