json_register/
errors.rs

1#[cfg(feature = "python")]
2use pyo3::exceptions::PyRuntimeError;
3#[cfg(feature = "python")]
4use pyo3::PyErr;
5use thiserror::Error;
6
7/// Errors that can occur during JSON registration.
8#[derive(Error, Debug)]
9pub enum JsonRegisterError {
10    /// An error occurred while interacting with the database.
11    #[error("Database error: {0}")]
12    DbError(#[from] sqlx::Error),
13
14    /// An error occurred while serializing or deserializing JSON.
15    #[error("Serialization error: {0}")]
16    SerdeError(#[from] serde_json::Error),
17
18    /// An invalid configuration was provided.
19    #[error("Configuration error: {0}")]
20    Configuration(String),
21
22    /// A runtime error occurred (e.g., initializing the Tokio runtime).
23    #[error("Runtime error: {0}")]
24    RuntimeError(String),
25
26    /// An error occurred during Python serialization/deserialization.
27    #[error("Python serialization error: {0}")]
28    SerializationError(String),
29}
30
31#[cfg(feature = "python")]
32impl From<JsonRegisterError> for PyErr {
33    fn from(err: JsonRegisterError) -> PyErr {
34        PyRuntimeError::new_err(err.to_string())
35    }
36}