Skip to main content

vision_calibration_core/
error.rs

1//! Typed error enum for `vision-calibration-core`.
2
3/// Errors returned by public APIs in `vision-calibration-core`.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7    /// Input data is invalid (e.g. mismatched lengths, negative weights).
8    #[error("invalid input: {reason}")]
9    InvalidInput { reason: String },
10
11    /// Not enough data to proceed (e.g. fewer correspondences than required).
12    #[error("insufficient data: need {need}, got {got}")]
13    InsufficientData { need: usize, got: usize },
14
15    /// A matrix inversion or decomposition produced a degenerate result.
16    #[error("singular matrix or degenerate configuration")]
17    Singular,
18
19    /// A numerical operation failed unexpectedly.
20    #[error("numerical failure: {0}")]
21    Numerical(String),
22}
23
24impl Error {
25    /// Convenience constructor for [`Error::InvalidInput`].
26    pub(crate) fn invalid_input(reason: impl Into<String>) -> Self {
27        Self::InvalidInput {
28            reason: reason.into(),
29        }
30    }
31}