feos_core/
errors.rs

1use num_dual::linalg::LinAlgError;
2use std::io;
3use thiserror::Error;
4
5/// Error type for improperly defined states and convergence problems.
6#[derive(Error, Debug)]
7pub enum FeosError {
8    // generic error with custom message
9    #[error("{0}")]
10    Error(String),
11
12    // errors related to algorithms
13    #[error("`{0}` did not converge within the maximum number of iterations.")]
14    NotConverged(String),
15    #[error("`{0}` encountered illegal values during the iteration.")]
16    IterationFailed(String),
17    #[error("Iteration resulted in trivial solution.")]
18    TrivialSolution,
19    #[error(
20        "Equation of state is initialized for {0} components while the input specifies {1} components."
21    )]
22    IncompatibleComponents(usize, usize),
23    #[error("Invalid state in {0}: {1} = {2}.")]
24    InvalidState(String, String, f64),
25    #[error("Undetermined state: {0}.")]
26    UndeterminedState(String),
27    #[error("System is supercritical.")]
28    SuperCritical,
29    #[error("No phase split according to stability analysis.")]
30    NoPhaseSplit,
31    #[error("Wrong input units. Expected {0}, got {1}")]
32    WrongUnits(String, String),
33
34    // errors related to file handling
35    #[error(transparent)]
36    FileIO(#[from] io::Error),
37
38    // json errors
39    #[error(transparent)]
40    Serde(#[from] serde_json::Error),
41
42    // errors related to parameter handling
43    #[error("The following component(s) were not found: {0}")]
44    ComponentsNotFound(String),
45    #[error(
46        "The identifier '{0}' is not known. ['cas', 'name', 'iupacname', 'smiles', inchi', 'formula']"
47    )]
48    IdentifierNotFound(String),
49    #[error("Information missing.")]
50    InsufficientInformation,
51    #[error("Incompatible parameters: {0}")]
52    IncompatibleParameters(String),
53    #[error("Missing parameters: {0}")]
54    MissingParameters(String),
55
56    // other errors
57    #[error(transparent)]
58    LinAlgError(#[from] LinAlgError),
59    #[cfg(feature = "rayon")]
60    #[error(transparent)]
61    RayonError(#[from] rayon::ThreadPoolBuildError),
62    #[cfg(feature = "ndarray")]
63    #[error(transparent)]
64    ShapeError(#[from] ndarray::ShapeError),
65}
66
67/// Convenience type for `Result<T, FeosError>`.
68pub type FeosResult<T> = Result<T, FeosError>;