use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConfigError {
IoOpen {
path: PathBuf,
err: String,
},
Parse {
line: usize,
col: usize,
msg: String,
},
Schema {
line: usize,
field: String,
msg: String,
},
}
impl std::fmt::Display for ConfigError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::IoOpen { path, err } => {
write!(f, "kevy-config: cannot read {}: {err}", path.display())
}
Self::Parse { line, col, msg } => {
write!(f, "kevy-config: parse error at line {line} col {col}: {msg}")
}
Self::Schema { line, field, msg } => {
write!(f, "kevy-config: schema error at line {line} on {field}: {msg}")
}
}
}
}
impl std::error::Error for ConfigError {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ValueError {
msg: String,
}
impl ValueError {
pub(crate) fn new(msg: impl Into<String>) -> Self {
Self { msg: msg.into() }
}
}
impl std::fmt::Display for ValueError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.msg)
}
}
impl std::error::Error for ValueError {}