48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
|
#[derive(Debug, Clone)]
|
||
|
pub enum UpEndError {
|
||
|
HashDecodeError(String),
|
||
|
AddressParseError(String),
|
||
|
AddressComponentsDecodeError(AddressComponentsDecodeError),
|
||
|
CannotSerializeInvalid,
|
||
|
Other(String),
|
||
|
}
|
||
|
|
||
|
#[derive(Debug, Clone)]
|
||
|
pub enum AddressComponentsDecodeError {
|
||
|
UnknownType(String),
|
||
|
UrlDecodeError(String),
|
||
|
MissingValue,
|
||
|
}
|
||
|
|
||
|
impl std::fmt::Display for UpEndError {
|
||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
write!(
|
||
|
f,
|
||
|
"{}",
|
||
|
match self {
|
||
|
UpEndError::HashDecodeError(err) => format!("Could not decode hash: {err}"),
|
||
|
UpEndError::AddressParseError(err) => format!("Error parsing address: {err}"),
|
||
|
UpEndError::AddressComponentsDecodeError(cde) => match cde {
|
||
|
AddressComponentsDecodeError::UnknownType(t) =>
|
||
|
format!("Unknown type: \"{t}\""),
|
||
|
AddressComponentsDecodeError::MissingValue =>
|
||
|
String::from("Address type requires a value."),
|
||
|
AddressComponentsDecodeError::UrlDecodeError(err) =>
|
||
|
format!("Couldn't decode URL: {err}"),
|
||
|
},
|
||
|
UpEndError::CannotSerializeInvalid =>
|
||
|
String::from("Invalid EntryValues cannot be serialized."),
|
||
|
UpEndError::Other(err) => format!("Unknown error: {err}"),
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl std::error::Error for UpEndError {}
|
||
|
|
||
|
impl UpEndError {
|
||
|
pub fn from_any<E: std::fmt::Display>(error: E) -> Self {
|
||
|
UpEndError::Other(error.to_string())
|
||
|
}
|
||
|
}
|