graphrecords_python/graphrecord/
errors.rs1use graphrecords_core::errors::{GraphError, GraphRecordError};
2use pyo3::{
3 PyErr,
4 exceptions::{PyAssertionError, PyIndexError, PyKeyError, PyRuntimeError, PyValueError},
5};
6
7#[repr(transparent)]
8pub struct PyGraphRecordError(GraphRecordError);
9pub type PyGraphRecordResult<T> = Result<T, PyGraphRecordError>;
10
11impl From<GraphRecordError> for PyGraphRecordError {
12 fn from(error: GraphRecordError) -> Self {
13 Self(error)
14 }
15}
16
17impl From<GraphError> for PyGraphRecordError {
18 fn from(error: GraphError) -> Self {
19 Self(GraphRecordError::from(error))
20 }
21}
22
23impl From<PyGraphRecordError> for PyErr {
24 fn from(error: PyGraphRecordError) -> Self {
25 match error.0 {
26 GraphRecordError::IndexError(message) => PyIndexError::new_err(message),
27 GraphRecordError::KeyError(message) => PyKeyError::new_err(message),
28 GraphRecordError::ConversionError(message) | GraphRecordError::QueryError(message) => {
29 PyRuntimeError::new_err(message)
30 }
31 GraphRecordError::AssertionError(message) => PyAssertionError::new_err(message),
32 GraphRecordError::SchemaError(message) => PyValueError::new_err(message),
33 }
34 }
35}