use std::error::Error;
use std::fmt::{Debug, Display, Formatter, Result as FResult};
use std::path::PathBuf;
#[derive(Debug)]
pub enum CertsError {
ClientCertParseError { err: x509_parser::nom::Err<x509_parser::error::X509Error> },
ClientCertNoCN { subject: String },
FileOpenError { what: &'static str, path: PathBuf, err: std::io::Error },
FileReadError { what: &'static str, path: PathBuf, err: std::io::Error },
UnknownItemError { what: &'static str, path: PathBuf },
CertFileParseError { path: PathBuf, err: std::io::Error },
KeyFileParseError { path: PathBuf, err: std::io::Error },
EmptyCertFile { path: PathBuf },
EmptyKeyFile { path: PathBuf },
}
impl Display for CertsError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
use CertsError::*;
match self {
ClientCertParseError { err } => write!(f, "Failed to parse given client certificate file: {err}"),
ClientCertNoCN { subject } => write!(f, "Certificate subject field '{subject}' does not specify a CN"),
FileOpenError { what, path, err } => write!(f, "Failed to open {} file '{}': {}", what, path.display(), err),
FileReadError { what, path, err } => write!(f, "Failed to read {} file '{}': {}", what, path.display(), err),
UnknownItemError { what, path } => write!(f, "Encountered non-certificate, non-key item in {} file '{}'", what, path.display()),
CertFileParseError { path, err } => write!(f, "Failed to parse certificates in '{}': {}", path.display(), err),
KeyFileParseError { path, err } => write!(f, "Failed to parse keys in '{}': {}", path.display(), err),
EmptyCertFile { path } => write!(f, "No certificates found in file '{}'", path.display()),
EmptyKeyFile { path } => write!(f, "No keys found in file '{}'", path.display()),
}
}
}
impl Error for CertsError {}
#[derive(Debug)]
pub enum NodeConfigError {
FileOpenError { path: PathBuf, err: std::io::Error },
FileReadError { path: PathBuf, err: std::io::Error },
FileParseError { path: PathBuf, err: serde_yaml::Error },
FileCreateError { path: PathBuf, err: std::io::Error },
FileWriteError { path: PathBuf, err: std::io::Error },
ConfigSerializeError { err: serde_yaml::Error },
WriterWriteError { err: std::io::Error },
}
impl Display for NodeConfigError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
use NodeConfigError::*;
match self {
FileOpenError { path, err } => write!(f, "Failed to open the node config file '{}': {}", path.display(), err),
FileReadError { path, err } => write!(f, "Failed to read the ndoe config file '{}': {}", path.display(), err),
FileParseError { path, err } => write!(f, "Failed to parse node config file '{}' as YAML: {}", path.display(), err),
FileCreateError { path, err } => write!(f, "Failed to create the node config file '{}': {}", path.display(), err),
FileWriteError { path, err } => write!(f, "Failed to write to the ndoe config file '{}': {}", path.display(), err),
ConfigSerializeError { err } => write!(f, "Failed to serialize node config to YAML: {err}"),
WriterWriteError { err } => write!(f, "Failed to write to given writer: {err}"),
}
}
}
impl Error for NodeConfigError {}
#[derive(Debug)]
pub enum ProxyProtocolParseError {
UnknownProtocol { raw: String },
}
impl Display for ProxyProtocolParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
use ProxyProtocolParseError::*;
match self {
UnknownProtocol { raw } => write!(f, "Unknown proxy protocol '{raw}'"),
}
}
}
impl Error for ProxyProtocolParseError {}
#[derive(Debug)]
pub enum NodeKindParseError {
UnknownNodeKind { raw: String },
}
impl Display for NodeKindParseError {
fn fmt(&self, f: &mut Formatter<'_>) -> FResult {
use NodeKindParseError::*;
match self {
UnknownNodeKind { raw } => write!(f, "Unknown node kind '{raw}'"),
}
}
}
impl Error for NodeKindParseError {}