1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Redis connection error: {0}. Check that Redis is running and accessible.")]
13 Connection(#[from] redis::RedisError),
14
15 #[error("Invalid Redis URL '{0}'. Expected format: redis://[user:password@]host[:port][/db]")]
17 InvalidUrl(String),
18
19 #[error("Schema mismatch: {0}. Ensure the schema matches the Redis data structure.")]
21 SchemaMismatch(String),
22
23 #[error("Type conversion error: {0}. Check that the schema types match the actual data.")]
25 TypeConversion(String),
26
27 #[error("IO error: {0}")]
29 Io(#[from] std::io::Error),
30
31 #[error("Runtime error: {0}")]
33 Runtime(String),
34
35 #[error("Key not found: {0}")]
37 KeyNotFound(String),
38
39 #[error("RedisJSON module not available. Install redis-stack or load the ReJSON module.")]
41 JsonModuleNotAvailable,
42
43 #[error("Invalid input: {0}")]
45 InvalidInput(String),
46
47 #[error("Key already exists: {0}")]
49 KeyExists(String),
50
51 #[error("Channel error: {0}")]
53 Channel(String),
54}
55
56#[cfg(feature = "python")]
57impl From<Error> for pyo3::PyErr {
58 fn from(err: Error) -> pyo3::PyErr {
59 match err {
60 Error::Connection(_) | Error::InvalidUrl(_) => {
61 pyo3::exceptions::PyConnectionError::new_err(err.to_string())
62 }
63 Error::SchemaMismatch(_) | Error::TypeConversion(_) => {
64 pyo3::exceptions::PyValueError::new_err(err.to_string())
65 }
66 Error::Io(_) => pyo3::exceptions::PyIOError::new_err(err.to_string()),
67 Error::Runtime(_) => pyo3::exceptions::PyRuntimeError::new_err(err.to_string()),
68 Error::KeyNotFound(_) => pyo3::exceptions::PyKeyError::new_err(err.to_string()),
69 Error::JsonModuleNotAvailable => {
70 pyo3::exceptions::PyRuntimeError::new_err(err.to_string())
71 }
72 Error::InvalidInput(_) => pyo3::exceptions::PyValueError::new_err(err.to_string()),
73 Error::KeyExists(_) => pyo3::exceptions::PyValueError::new_err(err.to_string()),
74 Error::Channel(_) => pyo3::exceptions::PyRuntimeError::new_err(err.to_string()),
75 }
76 }
77}