1use pyo3::PyErr;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
6pub enum StrSimError {
7 #[error("Invalid input data: {0}")]
9 InvalidInputData(String),
10 #[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 #[error(transparent)]
28 IOError(#[from] std::io::Error),
29
30 #[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}