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

Function to_py_runtime_error

python/src/errors.rs:190–211  ·  view source on GitHub ↗

Enhanced utility function to convert any error to PyErr with context

(error: E)

Source from the content-addressed store, hash-verified

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 {
191 let error_msg = error.to_string();
192 warn!(
193 "Converting runtime error to Python exception: {}",
194 error_msg
195 );
196
197 // Check for common error patterns and map to appropriate exceptions
198 if error_msg.contains("timeout") || error_msg.contains("deadline") {
199 PyErr::new::<pyo3::exceptions::PyTimeoutError, _>(error_msg)
200 } else if error_msg.contains("permission") || error_msg.contains("unauthorized") {
201 PyErr::new::<pyo3::exceptions::PyPermissionError, _>(error_msg)
202 } else if error_msg.contains("not found") || error_msg.contains("missing") {
203 PyErr::new::<pyo3::exceptions::PyFileNotFoundError, _>(error_msg)
204 } else if error_msg.contains("invalid") || error_msg.contains("malformed") {
205 PyErr::new::<pyo3::exceptions::PyValueError, _>(error_msg)
206 } else if error_msg.contains("connection") || error_msg.contains("network") {
207 PyErr::new::<pyo3::exceptions::PyConnectionError, _>(error_msg)
208 } else {
209 PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(error_msg)
210 }
211}
212
213/// Create validation error with field and value context
214pub(crate) fn validation_error(field: &str, value: Option<&str>, message: &str) -> PyErr {

Callers 4

initFunction · 0.85
executeMethod · 0.85
run_asyncMethod · 0.85
connectMethod · 0.85

Calls 1

to_stringMethod · 0.80

Tested by

no test coverage detected