1use std::string::FromUtf8Error;
2
3use thiserror::Error;
4
5#[derive(Error, Debug, Clone, PartialEq, Eq)]
6pub enum ToKlvmError {
7 #[error("out of memory")]
8 OutOfMemory,
9
10 #[error("{0}")]
11 Custom(String),
12}
13
14#[derive(Error, Debug, Clone, PartialEq, Eq)]
15pub enum FromKlvmError {
16 #[error("{0}")]
17 InvalidUtf8(#[from] FromUtf8Error),
18
19 #[error("expected atom of length {expected}, but found length {found}")]
20 WrongAtomLength { expected: usize, found: usize },
21
22 #[error("expected atom")]
23 ExpectedAtom,
24
25 #[error("expected pair")]
26 ExpectedPair,
27
28 #[error("{0}")]
29 Custom(String),
30}
31
32#[cfg(feature = "py-bindings")]
33use pyo3::PyErr;
34
35#[cfg(feature = "py-bindings")]
36impl From<ToKlvmError> for PyErr {
37 fn from(err: ToKlvmError) -> PyErr {
38 pyo3::exceptions::PyValueError::new_err(err.to_string())
39 }
40}
41
42#[cfg(feature = "py-bindings")]
43impl From<FromKlvmError> for PyErr {
44 fn from(err: FromKlvmError) -> PyErr {
45 pyo3::exceptions::PyValueError::new_err(err.to_string())
46 }
47}