use core::fmt;
#[derive(Debug)]
#[non_exhaustive]
pub enum ArcsecError {
Singular,
InsufficientStars {
found: usize,
required: usize,
},
InsufficientQuads {
found: usize,
required: usize,
},
BadSolution {
ratio: f64,
},
CatalogNotFound(std::path::PathBuf),
CatalogIo(std::io::Error),
InvalidParameter(String),
}
impl fmt::Display for ArcsecError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Singular => write!(f, "singular matrix in LSQ solver"),
Self::InsufficientStars { found, required } => {
write!(f, "insufficient stars: found {found}, required {required}")
}
Self::InsufficientQuads { found, required } => {
write!(f, "insufficient quads: found {found}, required {required}")
}
Self::BadSolution { ratio } => {
write!(
f,
"bad solution: xy scale ratio {ratio:.4} not in [0.9, 1.1]"
)
}
Self::CatalogNotFound(p) => write!(f, "catalog not found: {}", p.display()),
Self::CatalogIo(e) => write!(f, "catalog I/O error: {e}"),
Self::InvalidParameter(msg) => write!(f, "invalid parameter: {msg}"),
}
}
}
impl core::error::Error for ArcsecError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
Self::CatalogIo(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for ArcsecError {
fn from(e: std::io::Error) -> Self {
Self::CatalogIo(e)
}
}
pub type Result<T> = core::result::Result<T, ArcsecError>;