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}
25
26impl ParamError {
27    /// Check if the trim parameter is valid
28    pub fn check_trim(value: &str) -> Result<(), Self> {
29        if !(value == "fb" || value == "f" || value == "b") {
30            return Err(ParamError::InvalidTrimParam {
31                value: value.to_string(),
32                location: Location::caller(),
33            }
34            .into());
35        }
36        Ok(())
37    }
38}