use toml_edit::TomlError;
#[derive(Debug)]
pub enum Error {
DefaultParse {
source: TomlError,
},
UserParse {
source: TomlError,
},
DefaultsDeclareNoKeys,
MigrationPath {
source: TomlError,
},
SetPath {
source: TomlError,
},
NotAValue {
path: String,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DefaultParse { source } => {
write!(f, "the default document does not parse: {source}")
}
Self::UserParse { source } => write!(f, "the user document does not parse: {source}"),
Self::DefaultsDeclareNoKeys => f.write_str("the default document declares no keys"),
Self::MigrationPath { source } => {
write!(f, "a rename rule has an unreadable path: {source}")
}
Self::SetPath { source } => write!(f, "unreadable path: {source}"),
Self::NotAValue { path } => {
write!(f, "{path} holds a table, so no value can be set there")
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::DefaultParse { source }
| Self::UserParse { source }
| Self::MigrationPath { source }
| Self::SetPath { source } => Some(source),
Self::DefaultsDeclareNoKeys | Self::NotAValue { .. } => None,
}
}
}