1#[cfg(feature = "python")]
3use pyo3::exceptions::{PyIOError, PyValueError};
4#[cfg(feature = "python")]
5use pyo3::PyErr;
6use thiserror::Error;
7
8#[derive(Error, Debug)]
10pub enum DmapError {
11 #[error("{0}")]
13 CorruptStream(&'static str),
14
15 #[error(transparent)]
17 Io(#[from] std::io::Error),
18
19 #[error(transparent)]
21 BadCast(#[from] std::num::TryFromIntError),
22
23 #[error("{0}")]
25 InvalidKey(i8),
26
27 #[error("{0}")]
30 InvalidRecord(String),
31
32 #[error("{0}")]
34 InvalidScalar(String),
35
36 #[error("{0}")]
38 InvalidVector(String),
39
40 #[error("{0}")]
42 InvalidField(String),
43
44 #[error("{0}")]
46 InvalidIndex(i32),
47
48 #[error("First error: {1}\nRecords with errors: {0:?}")]
50 BadRecords(Vec<usize>, String),
51}
52
53#[cfg(feature = "python")]
54impl From<DmapError> for PyErr {
55 fn from(value: DmapError) -> Self {
56 let msg = value.to_string();
57 match value {
58 DmapError::CorruptStream(..) => PyIOError::new_err(msg),
59 DmapError::Io(..) => PyIOError::new_err(msg),
60 _ => PyValueError::new_err(msg),
61 }
62 }
63}