use std::{io, path::PathBuf};
pub type AppResult<T> = Result<T, AppError>;
#[derive(Debug, thiserror::Error)]
pub enum AppError {
#[error("failed to read config file `{path}`: {source}")]
ConfigRead {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("invalid TOML in `{path}`{canonical_display}: {source}", canonical_display = match canonical {
Some(p) => format!(" ({})", p.display()),
None => String::new(),
})]
ConfigParse {
path: PathBuf,
canonical: Option<PathBuf>,
#[source]
source: toml::de::Error,
},
#[error("failed to read rule set file `{path}`: {source}")]
RuleSetRead {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("invalid rule set TOML in `{path}`{canonical_display}: {source}", canonical_display = match canonical {
Some(p) => format!(" ({})", p.display()),
None => String::new(),
})]
RuleSetParse {
path: PathBuf,
canonical: Option<PathBuf>,
#[source]
source: toml::de::Error,
},
#[error("middleware script not found: `{path}`")]
MiddlewareMissing { path: PathBuf },
#[error("failed to compile middleware `{path}`: {reason}")]
MiddlewareCompile { path: PathBuf, reason: String },
#[error("TLS material load failed ({kind}) at `{path}`: {reason}")]
TlsLoad {
kind: TlsKind,
path: PathBuf,
reason: String,
},
#[error("invalid listener address `{addr}`: {reason}")]
ListenerAddress { addr: String, reason: String },
#[error("configuration validation failed")]
Validation,
#[error("failed to resolve path `{path}`: {source}")]
PathResolve {
path: PathBuf,
#[source]
source: io::Error,
},
#[error("i/o error: {0}")]
Io(#[from] io::Error),
}
#[derive(Debug, Clone, Copy)]
pub enum TlsKind {
Certificate,
PrivateKey,
}
impl std::fmt::Display for TlsKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TlsKind::Certificate => f.write_str("certificate"),
TlsKind::PrivateKey => f.write_str("private key"),
}
}
}