1use std::error::Error;
2use std::fmt;
3
4use use_stoichiometry::StoichiometryValidationError;
5
6#[derive(Clone, Debug, Eq, PartialEq)]
8pub enum ReactionValidationError {
9 EmptyReaction,
11 MissingReactants,
13 MissingProducts,
15 EmptyCatalystLabel,
17 EmptySolventLabel,
19 EmptyTemperatureLabel,
21 EmptyPressureLabel,
23 EmptyConditionLabel,
25 EmptyConditionValue,
27 InvalidStoichiometry(StoichiometryValidationError),
29}
30
31impl fmt::Display for ReactionValidationError {
32 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
33 match self {
34 Self::EmptyReaction => {
35 formatter.write_str("reaction must contain reactants and products")
36 },
37 Self::MissingReactants => {
38 formatter.write_str("reaction must contain at least one reactant")
39 },
40 Self::MissingProducts => {
41 formatter.write_str("reaction must contain at least one product")
42 },
43 Self::EmptyCatalystLabel => formatter.write_str("catalyst label must not be empty"),
44 Self::EmptySolventLabel => formatter.write_str("solvent label must not be empty"),
45 Self::EmptyTemperatureLabel => {
46 formatter.write_str("temperature label must not be empty")
47 },
48 Self::EmptyPressureLabel => formatter.write_str("pressure label must not be empty"),
49 Self::EmptyConditionLabel => formatter.write_str("condition label must not be empty"),
50 Self::EmptyConditionValue => formatter.write_str("condition value must not be empty"),
51 Self::InvalidStoichiometry(error) => {
52 write!(formatter, "invalid stoichiometry: {error}")
53 },
54 }
55 }
56}
57
58impl Error for ReactionValidationError {
59 fn source(&self) -> Option<&(dyn Error + 'static)> {
60 match self {
61 Self::InvalidStoichiometry(error) => Some(error),
62 _ => None,
63 }
64 }
65}
66
67impl From<StoichiometryValidationError> for ReactionValidationError {
68 fn from(error: StoichiometryValidationError) -> Self {
69 Self::InvalidStoichiometry(error)
70 }
71}