use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Error)]
#[non_exhaustive]
pub enum Error {
#[error("could not parse coordinate: {0}")]
ParseCoord(String),
#[error("could not parse date: {0}")]
ParseDate(String),
#[error("unknown constellation abbreviation: {0}")]
UnknownConstellation(String),
#[error("{what} out of range: {value}")]
OutOfRange {
what: &'static str,
value: f64,
},
}
pub type Result<T> = core::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_messages() {
assert_eq!(
Error::ParseCoord("x".into()).to_string(),
"could not parse coordinate: x"
);
assert_eq!(
Error::ParseDate("y".into()).to_string(),
"could not parse date: y"
);
assert_eq!(
Error::OutOfRange {
what: "declination",
value: 91.0
}
.to_string(),
"declination out of range: 91"
);
}
}