1use thiserror::Error;
4
5#[cfg(feature = "wasm")]
6use wasm_bindgen::JsValue;
7
8use crate::specs::Unit;
9
10#[derive(Error, Debug)]
12pub enum Error {
13 #[error("Preconditions for computing energy not met: {0}")]
15 CannotComputeEnergy(String),
16 #[error("Preconditions for computing POD not met: {0}")]
18 CannotComputePOD(String),
19 #[error("Preconditions for computing PAC not met: {0}")]
21 CannotComputePAC(String),
22 #[error("Composition is not within [0, 100]%: {0}")]
24 CompositionNotWithin100Percent(f64),
25 #[error("Composition does not sum to 100%: {0}")]
27 CompositionNot100Percent(f64),
28 #[error("Composition value is not positive: {0}")]
30 CompositionNotPositive(f64),
31 #[error("Invalid composition: {0}")]
33 InvalidComposition(String),
34 #[error("PAC value cannot be negative: {0}")]
36 NegativePacValue(f64),
37 #[error("FPD value cannot be positive: {0}")]
39 PositiveFpdValue(f64),
40 #[error("Composition unit is not supported for this operation: {0}")]
42 UnsupportedCompositionUnit(Unit),
43 #[error("Ingredient not found: {0}")]
45 IngredientNotFound(String),
46}
47
48#[cfg(feature = "wasm")]
49impl From<Error> for JsValue {
50 fn from(error: Error) -> Self {
51 Self::from_str(&error.to_string())
52 }
53}
54
55pub type Result<T> = std::result::Result<T, Error>;