target_match/error.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Error type for `target-match`.
6//!
7//! Every fallible entry point returns [`Result`]. The only construction this
8//! crate itself validates is optics/field geometry — coordinate parsing and
9//! domain checks happen in [`skymath`] when the consumer builds an
10//! [`skymath::Equatorial`], and surface as [`skymath::Error`]. Matching and
11//! precession are infallible once inputs are valid values.
12
13use thiserror::Error;
14
15/// Everything that can go wrong constructing `target-match` values.
16///
17/// # Example
18///
19/// ```
20/// use target_match::{Error, Field, Optics};
21///
22/// let err = Field::from_optics(Optics {
23/// focal_mm: 0.0, pixel_um: (3.76, 3.76), binning: (1, 1), pixels: (6248, 4176),
24/// })
25/// .unwrap_err();
26/// assert!(matches!(err, Error::InvalidOptics(_)));
27/// ```
28#[derive(Debug, Clone, PartialEq, Error)]
29#[non_exhaustive]
30pub enum Error {
31 /// Optics or field inputs were non-positive, non-finite, or insufficient to
32 /// derive a field of view.
33 #[error("invalid optics: {0}")]
34 InvalidOptics(String),
35}
36
37/// Convenience alias for `Result<T, `[`Error`](enum@Error)`>`.
38pub type Result<T> = core::result::Result<T, Error>;
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn display_messages() {
46 assert_eq!(
47 Error::InvalidOptics("focal <= 0".into()).to_string(),
48 "invalid optics: focal <= 0"
49 );
50 }
51}