Skip to main content

ronn/
error.rs

1//! Error handling for Python bindings
2
3use pyo3::exceptions::PyException;
4use pyo3::prelude::*;
5
6/// Python-facing error type
7#[derive(Debug)]
8pub struct RonnError(pub String);
9
10impl From<ronn_core::CoreError> for RonnError {
11    fn from(err: ronn_core::CoreError) -> Self {
12        RonnError(err.to_string())
13    }
14}
15
16impl From<ronn_api::Error> for RonnError {
17    fn from(err: ronn_api::Error) -> Self {
18        RonnError(err.to_string())
19    }
20}
21
22impl From<anyhow::Error> for RonnError {
23    fn from(err: anyhow::Error) -> Self {
24        RonnError(err.to_string())
25    }
26}
27
28impl From<pyo3::PyErr> for RonnError {
29    fn from(err: pyo3::PyErr) -> Self {
30        RonnError(err.to_string())
31    }
32}
33
34impl From<numpy::NotContiguousError> for RonnError {
35    fn from(err: numpy::NotContiguousError) -> Self {
36        RonnError(err.to_string())
37    }
38}
39
40impl From<RonnError> for PyErr {
41    fn from(err: RonnError) -> PyErr {
42        PyException::new_err(err.0)
43    }
44}
45
46pub type PyResult<T> = Result<T, RonnError>;