Convert Python binding errors to PyErr with appropriate exception types
(error: PythonBindingError)
| 162 | |
| 163 | /// Convert Python binding errors to PyErr with appropriate exception types |
| 164 | pub(crate) fn python_error_to_py_err(error: PythonBindingError) -> PyErr { |
| 165 | match &error { |
| 166 | PythonBindingError::Network { .. } => { |
| 167 | PyErr::new::<pyo3::exceptions::PyConnectionError, _>(error.to_string()) |
| 168 | } |
| 169 | PythonBindingError::Authentication { .. } => { |
| 170 | PyErr::new::<pyo3::exceptions::PyPermissionError, _>(error.to_string()) |
| 171 | } |
| 172 | PythonBindingError::Validation { .. } => { |
| 173 | PyErr::new::<pyo3::exceptions::PyValueError, _>(error.to_string()) |
| 174 | } |
| 175 | PythonBindingError::Configuration { .. } => { |
| 176 | PyErr::new::<pyo3::exceptions::PyValueError, _>(error.to_string()) |
| 177 | } |
| 178 | PythonBindingError::RateLimit { .. } => { |
| 179 | PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(error.to_string()) |
| 180 | } |
| 181 | PythonBindingError::Timeout { .. } => { |
| 182 | PyErr::new::<pyo3::exceptions::PyTimeoutError, _>(error.to_string()) |
| 183 | } |
| 184 | |
| 185 | _ => PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(error.to_string()), |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | /// Enhanced utility function to convert any error to PyErr with context |
| 190 | pub(crate) fn to_py_runtime_error<E: std::fmt::Display>(error: E) -> PyErr { |
no test coverage detected