use thiserror::Error;
#[derive(Error, Clone, Debug)]
pub enum Metadata {
#[error("unexpected end of file")]
UnexpectedEof,
#[error("mismatched tag: {0:?}")]
MismatchedTag(String),
#[error("{phase}: missing value: {name:?}")]
#[allow(unused)] MissingValue { phase: String, name: String },
#[error("{phase}: unhandled element: {name:?}")]
UnhandledElement { phase: String, name: String },
#[error("{phase}: unhandled attribute: {name:?}={value:?}")]
UnhandledAttribute {
phase: String,
name: String,
value: String,
},
#[error("{phase}: unhandled event: {event:?}")]
UnhandledEvent { phase: String, event: String },
}
#[derive(Error, Clone, Debug)]
pub enum Parse {
#[error("not a number")]
#[allow(unused)] NoNumber,
#[error("invalid country code")]
#[allow(unused)] InvalidCountryCode,
#[error("the number is too short after IDD")]
#[allow(unused)] TooShortAfterIdd,
#[error("the number is too short after the country code")]
#[allow(unused)] TooShortNsn,
#[error("the number is too long")]
#[allow(unused)] TooLong,
#[error("malformed integer part in phone number: {0}")]
MalformedInteger(#[from] std::num::ParseIntError),
}
#[derive(Error, Debug)]
pub enum LoadMetadata {
#[error("Malformed Metadata XML: {0}")]
Xml(#[from] xml::Error),
#[error("Non UTF-8 string in Metadata XML: {0}")]
Utf8(#[from] std::str::Utf8Error),
#[error("{0}")]
Metadata(#[from] Metadata),
#[error("Malformed integer in Metadata XML: {0}")]
Integer(#[from] std::num::ParseIntError),
#[error("Malformed boolean in Metadata XML: {0}")]
Bool(#[from] std::str::ParseBoolError),
#[error("I/O-Error in Metadata XML: {0}")]
Io(#[from] std::io::Error),
#[error("Malformed Regex: {0}")]
Regex(#[from] regex::Error),
}