fix(rust-bridge): support traced OCR errors
Some checks failed
ai-gateway image / ai-gateway release image (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled

This commit is contained in:
Yujong Lee 2026-09-11 13:56:33 -07:00 committed by yujonglee
parent fc7f15e9e3
commit bfea249305
2 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,7 @@
use litellm_core::error::Error;
use pyo3::exceptions::{PyRuntimeError, PyValueError};
use pyo3::prelude::*;
use std::fmt::{Display, Formatter};
pyo3::create_exception!(
_native,
@ -28,6 +29,21 @@ pub(crate) enum BridgeError {
Host(PyErr),
}
impl Display for BridgeError {
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::InvalidArgument(message) | Self::Declined(message) | Self::Internal(message) => {
formatter.write_str(message)
}
Self::Upstream { status, message } => match status {
Some(status) => write!(formatter, "{status}: {message}"),
None => formatter.write_str(message),
},
Self::Host(error) => Display::fmt(error, formatter),
}
}
}
impl From<BridgeError> for PyErr {
fn from(error: BridgeError) -> Self {
match error {

View file

@ -134,6 +134,10 @@ fn prepare_ocr(
})
}
fn identity_bridge_error(error: BridgeError) -> BridgeError {
error
}
bridge_route! {
sync = ocr,
asynchronous = aocr,
@ -159,7 +163,7 @@ bridge_route! {
call_completion: Option<Py<PyAny>>,
},
prepare = prepare_ocr,
errors = std::convert::identity,
errors = identity_bridge_error,
}
#[cfg(test)]