hpt_common/error/
param.rs

1use std::panic::Location;
2
3use thiserror::Error;
4
5/// Parameter-related errors such as invalid function arguments
6#[derive(Debug, Error)]
7pub enum ParamError {
8    /// Error that occurs when trim parameter is invalid
9    #[error("Invalid trim parameter: must be one of 'fb', 'f', 'b', got {value} at {location}")]
10    InvalidTrimParam {
11        /// Invalid trim value
12        value: String,
13        /// Location where error occurred
14        location: &'static Location<'static>,
15    },
16    /// Error that occurs when the axis is duplicated
17    #[error("Axis {axis} is duplicated at {location}")]
18    AxisDuplicated {
19        /// Duplicated axis
20        axis: i64,
21        /// Location where error occurred
22        location: &'static Location<'static>,
23    },
24    /// Error that occurs when FFT norm parameter is invalid
25    #[error("Invalid FFT norm parameter: must be one of 'backward', 'forward', 'ortho', got {value} at {location}")]
26    InvalidFFTNormParam {
27        /// Invalid FFT norm value
28        value: String,
29        /// Location where error occurred
30        location: &'static Location<'static>,
31    },
32}
33
34impl ParamError {
35    /// Check if the trim parameter is valid
36    pub fn check_trim(value: &str) -> Result<(), Self> {
37        if !(value == "fb" || value == "f" || value == "b") {
38            return Err(ParamError::InvalidTrimParam {
39                value: value.to_string(),
40                location: Location::caller(),
41            }
42            .into());
43        }
44        Ok(())
45    }
46}