yass/
error.rs

1use pyo3::PyErr;
2use thiserror::Error;
3
4/// Represent possible errors returned by this library.
5#[derive(Error, Debug)]
6pub enum StrSimError {
7    /// Represents errors that occur when the input data passing to the library is invalid.
8    #[error("Invalid input data: {0}")]
9    InvalidInputData(String),
10    /// Represents errors that occur when the configuration data passing to the library is invalid.
11    #[error("Invalid configuration: {0}")]
12    InvalidConfigData(String),
13
14    #[error("Integrity error - asking for an entity that isn't in the database: {0}")]
15    DBIntegrityError(String),
16
17    #[error("Generic integrity error: {0}")]
18    IntegrityError(String),
19
20    #[error("Logic error: {0}")]
21    LogicError(String),
22
23    #[error("Invalid arguments: {0}")]
24    InvalidArgument(String),
25
26    /// Represents all other cases of `std::io::Error`.
27    #[error(transparent)]
28    IOError(#[from] std::io::Error),
29
30    /// PyO3 error
31    #[error(transparent)]
32    PyErr(#[from] pyo3::PyErr),
33
34    #[error(transparent)]
35    LSAPErr(#[from] lsap::LSAPError),
36}
37
38pub fn into_pyerr<E: Into<StrSimError>>(err: E) -> PyErr {
39    let hderr = err.into();
40    if let StrSimError::PyErr(e) = hderr {
41        e
42    } else {
43        let anyerror: anyhow::Error = hderr.into();
44        anyerror.into()
45    }
46}