use crate::secrets;
use crate::values::UpDuration;
use core::fmt;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DaemonConfigError {
Toml(String),
BadEnvValue(&'static str, String),
BelowMinimum {
key: &'static str,
value: UpDuration,
min: UpDuration,
},
InvalidEnvironment(String),
}
impl core::error::Error for DaemonConfigError {}
impl fmt::Display for DaemonConfigError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Toml(m) => write!(f, "invalid shep.toml: {m}"),
Self::BadEnvValue(var, v) => write!(f, "invalid value `{v}` for {var}"),
Self::BelowMinimum { key, value, min } => {
write!(
f,
"invalid value `{value}` for {key}: must be at least {min}"
)
}
Self::InvalidEnvironment(value) => write!(
f,
"invalid value `{value}` for environment: must be 1-{} bytes of \
`[A-Za-z0-9._-]` not starting with `.`, and not `{}` (the secrets \
store's every-environment slot)",
secrets::MAX_KEY_BYTES,
secrets::ALL_ENVIRONMENTS
),
}
}
}