Skip to main content

lux_rs/
error.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum LuxError {
5    EmptyInput,
6    MismatchedLengths { wavelengths: usize, values: usize },
7    NonMonotonicWavelengths,
8    InvalidGridSpec,
9    InvalidInput(&'static str),
10    UnsupportedObserver(&'static str),
11    MissingObserver,
12    ParseError(&'static str),
13}
14
15impl Display for LuxError {
16    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Self::EmptyInput => write!(f, "input cannot be empty"),
19            Self::MismatchedLengths {
20                wavelengths,
21                values,
22            } => write!(
23                f,
24                "wavelength/value length mismatch: wavelengths={}, values={}",
25                wavelengths, values
26            ),
27            Self::NonMonotonicWavelengths => {
28                write!(f, "wavelengths must be strictly increasing")
29            }
30            Self::InvalidGridSpec => write!(f, "invalid wavelength grid specification"),
31            Self::InvalidInput(message) => write!(f, "invalid input: {}", message),
32            Self::UnsupportedObserver(name) => write!(f, "unsupported observer: {}", name),
33            Self::MissingObserver => write!(f, "an observer is required for this operation"),
34            Self::ParseError(message) => write!(f, "parse error: {}", message),
35        }
36    }
37}
38
39impl std::error::Error for LuxError {}
40
41pub type LuxResult<T> = Result<T, LuxError>;