MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / python_error_to_py_err

Function python_error_to_py_err

python/src/errors.rs:164–187  ·  view source on GitHub ↗

Convert Python binding errors to PyErr with appropriate exception types

(error: PythonBindingError)

Source from the content-addressed store, hash-verified

162
163/// Convert Python binding errors to PyErr with appropriate exception types
164pub(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
190pub(crate) fn to_py_runtime_error<E: std::fmt::Display>(error: E) -> PyErr {

Callers 3

to_py_errorFunction · 0.85
validation_errorFunction · 0.85
timeout_errorFunction · 0.85

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected