rerun_bindings/catalog/
errors.rsuse pyo3::exceptions::{PyConnectionError, PyValueError};
use pyo3::PyErr;
use std::error::Error as _;
use re_grpc_client::redap::ConnectionError;
use re_protos::manifest_registry::v1alpha1::ext::GetDatasetSchemaResponseError;
#[derive(Debug, thiserror::Error)]
#[expect(clippy::enum_variant_names)] enum ExternalError {
#[error("{0}")]
ConnectionError(#[from] ConnectionError),
#[error("{0}")]
TonicStatusError(#[from] tonic::Status),
#[error("{0}")]
UriError(#[from] re_uri::Error),
#[error("{0}")]
ChunkError(#[from] re_chunk::ChunkError),
#[error("{0}")]
ChunkStoreError(#[from] re_chunk_store::ChunkStoreError),
#[error("{0}")]
StreamError(#[from] re_grpc_client::StreamError),
#[error("{0}")]
ArrowError(#[from] arrow::error::ArrowError),
#[error("{0}")]
UrlParseError(#[from] url::ParseError),
#[error("{0}")]
DatafusionError(#[from] datafusion::error::DataFusionError),
#[error(transparent)]
CodecError(#[from] re_log_encoding::codec::CodecError),
}
impl From<re_protos::manifest_registry::v1alpha1::ext::GetDatasetSchemaResponseError>
for ExternalError
{
fn from(value: GetDatasetSchemaResponseError) -> Self {
match value {
GetDatasetSchemaResponseError::ArrowError(err) => err.into(),
GetDatasetSchemaResponseError::TypeConversionError(err) => {
re_grpc_client::StreamError::from(err).into()
}
}
}
}
impl From<ExternalError> for PyErr {
fn from(err: ExternalError) -> Self {
match err {
ExternalError::ConnectionError(err) => PyConnectionError::new_err(err.to_string()),
ExternalError::TonicStatusError(status) => {
let mut msg = format!(
"tonic status error: {} (code: {}",
status.message(),
status.code()
);
if let Some(source) = status.source() {
msg.push_str(&format!(", source: {source})"));
} else {
msg.push(')');
}
PyConnectionError::new_err(msg)
}
ExternalError::UriError(err) => PyValueError::new_err(format!("Invalid URI: {err}")),
ExternalError::ChunkError(err) => PyValueError::new_err(format!("Chunk error: {err}")),
ExternalError::ChunkStoreError(err) => {
PyValueError::new_err(format!("Chunk store error: {err}"))
}
ExternalError::StreamError(err) => {
PyValueError::new_err(format!("Data streaming error: {err}"))
}
ExternalError::ArrowError(err) => PyValueError::new_err(format!("Arrow error: {err}")),
ExternalError::UrlParseError(err) => {
PyValueError::new_err(format!("Could not parse URL: {err}"))
}
ExternalError::DatafusionError(err) => {
PyValueError::new_err(format!("DataFusion error: {err}"))
}
ExternalError::CodecError(err) => PyValueError::new_err(format!("Codec error: {err}")),
}
}
}
#[expect(private_bounds)] pub fn to_py_err(err: impl Into<ExternalError>) -> PyErr {
err.into().into()
}