Skip to main content

sidereon_core/
error.rs

1//! Crate error type.
2//!
3//! The variants cover broad parsing, lookup, interpolation, and invalid-input
4//! failures across the crate.
5
6use core::fmt;
7
8/// Result alias for fallible `sidereon-core` operations.
9pub type Result<T> = core::result::Result<T, Error>;
10
11/// Errors produced by the `sidereon-core` crate.
12#[derive(Debug, Clone, PartialEq, Eq)]
13#[non_exhaustive]
14pub enum Error {
15    /// A product (SP3/RINEX/IONEX) could not be parsed.
16    Parse(String),
17    /// A requested satellite is not present in the product.
18    UnknownSatellite(crate::GnssSatelliteId),
19    /// A requested terrain tile is not present in the terrain store.
20    MissingTerrainTile {
21        /// Integer latitude tile id.
22        lat_index: i32,
23        /// Integer longitude tile id.
24        lon_index: i32,
25    },
26    /// An IONEX slant-delay query lies outside the product coverage.
27    IonexOutOfCoverage(crate::ionex::IonexCoverageError),
28    /// A requested epoch lies outside the sampled / valid span.
29    EpochOutOfRange,
30    /// An operation received inputs it cannot combine (e.g. an empty set of
31    /// products to merge, or products on mismatched time scales, epoch grids, or
32    /// coordinate-system labels).
33    InvalidInput(String),
34}
35
36impl fmt::Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Error::Parse(msg) => write!(f, "parse error: {msg}"),
40            Error::UnknownSatellite(id) => write!(f, "unknown satellite: {id}"),
41            Error::MissingTerrainTile {
42                lat_index,
43                lon_index,
44            } => write!(f, "missing terrain tile ({lat_index},{lon_index})"),
45            Error::IonexOutOfCoverage(error) => write!(f, "IONEX out of coverage: {error}"),
46            Error::EpochOutOfRange => write!(f, "epoch out of range"),
47            Error::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
48        }
49    }
50}
51
52impl std::error::Error for Error {}