Skip to content

Commit 654c013

Browse files
authored
fix: display kernel-rs errors better (#3883)
# Description Objectstore errors surfacing from kernel are not displayed nicely in python :) Signed-off-by: Ion Koutsouris <[email protected]>
1 parent e2409aa commit 654c013

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

python/src/error.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use arrow_schema::ArrowError;
22
use deltalake::datafusion::error::DataFusionError;
3+
use deltalake::kernel::Error as KernelError;
34
use deltalake::{errors::DeltaTableError, ObjectStoreError};
45
use pyo3::exceptions::{
56
PyException, PyFileNotFoundError, PyIOError, PyNotImplementedError, PyRuntimeError,
@@ -35,7 +36,12 @@ fn inner_to_py_err(err: DeltaTableError) -> PyErr {
3536
DeltaTableError::Transaction { source } => CommitFailedError::new_err(source.to_string()),
3637

3738
// python exceptions
38-
DeltaTableError::ObjectStore { source } => object_store_to_py(source),
39+
DeltaTableError::ObjectStore { source } => object_store_to_py(source, None),
40+
DeltaTableError::Kernel { source } => match source {
41+
KernelError::ObjectStore(e) => object_store_to_py(e, Some("Kernel error".to_string())),
42+
other => DeltaError::new_err(DeltaTableError::Kernel { source: other }.to_string()),
43+
},
44+
3945
DeltaTableError::Io { source } => PyIOError::new_err(source.to_string()),
4046

4147
DeltaTableError::Arrow { source } => arrow_to_py(source),
@@ -91,27 +97,37 @@ impl<T: Error + 'static> Display for DisplaySourceChain<T> {
9197
}
9298
}
9399

94-
fn object_store_to_py(err: ObjectStoreError) -> PyErr {
95-
match err {
96-
ObjectStoreError::NotFound { .. } => PyFileNotFoundError::new_err(
100+
fn object_store_to_py(err: ObjectStoreError, source_error: Option<String>) -> PyErr {
101+
if let Some(source_error) = source_error {
102+
PyIOError::new_err(
97103
DisplaySourceChain {
98104
err,
99-
error_name: "FileNotFoundError".to_string(),
105+
error_name: format!("{} -> IOError", source_error),
100106
}
101107
.to_string(),
102-
),
103-
ObjectStoreError::Generic { source, .. }
104-
if source.to_string().contains("AWS_S3_ALLOW_UNSAFE_RENAME") =>
105-
{
106-
DeltaProtocolError::new_err(source.to_string())
107-
}
108-
_ => PyIOError::new_err(
109-
DisplaySourceChain {
110-
err,
111-
error_name: "IOError".to_string(),
108+
)
109+
} else {
110+
match err {
111+
ObjectStoreError::NotFound { .. } => PyFileNotFoundError::new_err(
112+
DisplaySourceChain {
113+
err,
114+
error_name: "FileNotFoundError".to_string(),
115+
}
116+
.to_string(),
117+
),
118+
ObjectStoreError::Generic { source, .. }
119+
if source.to_string().contains("AWS_S3_ALLOW_UNSAFE_RENAME") =>
120+
{
121+
DeltaProtocolError::new_err(source.to_string())
112122
}
113-
.to_string(),
114-
),
123+
_ => PyIOError::new_err(
124+
DisplaySourceChain {
125+
err,
126+
error_name: "IOError".to_string(),
127+
}
128+
.to_string(),
129+
),
130+
}
115131
}
116132
}
117133

@@ -154,7 +170,7 @@ impl From<PythonError> for pyo3::PyErr {
154170
fn from(value: PythonError) -> Self {
155171
match value {
156172
PythonError::DeltaTable(err) => inner_to_py_err(err),
157-
PythonError::ObjectStore(err) => object_store_to_py(err),
173+
PythonError::ObjectStore(err) => object_store_to_py(err, None),
158174
PythonError::Arrow(err) => arrow_to_py(err),
159175
PythonError::DataFusion(err) => datafusion_to_py(err),
160176
PythonError::ThreadingError(err) => PyRuntimeError::new_err(err),

0 commit comments

Comments
 (0)