Skip to content

Print both display and debug output for errors #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion obstore/python/obstore/_get.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class BytesStream:
file is large, it may exceed the default timeout of 30 seconds. In this case,
you may see an error like:

x
```
GenericError: Generic {
store: "HTTP",
Expand Down
34 changes: 19 additions & 15 deletions pyo3-object_store/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,55 +103,59 @@ pub enum PyObjectStoreError {

impl From<PyObjectStoreError> for PyErr {
fn from(error: PyObjectStoreError) -> Self {
// #? gives "pretty-printing" in the errors
// https://doc.rust-lang.org/std/fmt/trait.Debug.html
match error {
PyObjectStoreError::PyErr(err) => err,
PyObjectStoreError::ObjectStoreError(ref err) => match err {
object_store::Error::Generic {
store: _,
source: _,
} => GenericError::new_err(err.to_string()),
} => GenericError::new_err(print_with_debug(err)),
object_store::Error::NotFound { path: _, source: _ } => {
PyFileNotFoundError::new_err(format!("{err:#?}"))
PyFileNotFoundError::new_err(print_with_debug(err))
}
object_store::Error::InvalidPath { source: _ } => {
InvalidPathError::new_err(format!("{err:#?}"))
InvalidPathError::new_err(print_with_debug(err))
}
object_store::Error::JoinError { source: _ } => {
JoinError::new_err(format!("{err:#?}"))
JoinError::new_err(print_with_debug(err))
}
object_store::Error::NotSupported { source: _ } => {
NotSupportedError::new_err(format!("{err:#?}"))
NotSupportedError::new_err(print_with_debug(err))
}
object_store::Error::AlreadyExists { path: _, source: _ } => {
AlreadyExistsError::new_err(format!("{err:#?}"))
AlreadyExistsError::new_err(print_with_debug(err))
}
object_store::Error::Precondition { path: _, source: _ } => {
PreconditionError::new_err(format!("{err:#?}"))
PreconditionError::new_err(print_with_debug(err))
}
object_store::Error::NotModified { path: _, source: _ } => {
NotModifiedError::new_err(format!("{err:#?}"))
NotModifiedError::new_err(print_with_debug(err))
}
object_store::Error::NotImplemented => {
PyNotImplementedError::new_err(format!("{err:#?}"))
PyNotImplementedError::new_err(print_with_debug(err))
}
object_store::Error::PermissionDenied { path: _, source: _ } => {
PermissionDeniedError::new_err(format!("{err:#?}"))
PermissionDeniedError::new_err(print_with_debug(err))
}
object_store::Error::Unauthenticated { path: _, source: _ } => {
UnauthenticatedError::new_err(format!("{err:#?}"))
UnauthenticatedError::new_err(print_with_debug(err))
}
object_store::Error::UnknownConfigurationKey { store: _, key: _ } => {
UnknownConfigurationKeyError::new_err(format!("{err:#?}"))
UnknownConfigurationKeyError::new_err(print_with_debug(err))
}
_ => GenericError::new_err(err.to_string()),
},
PyObjectStoreError::IOError(err) => PyIOError::new_err(format!("{err:#?}")),
PyObjectStoreError::IOError(err) => PyIOError::new_err(err),
}
}
}

fn print_with_debug(err: &object_store::Error) -> String {
// #? gives "pretty-printing" for debug
// https://doc.rust-lang.org/std/fmt/trait.Debug.html
format!("{err}\n\nDebug source:\n{err:#?}")
}

impl<'a, 'py> From<DowncastError<'a, 'py>> for PyObjectStoreError {
fn from(other: DowncastError<'a, 'py>) -> Self {
Self::PyErr(PyValueError::new_err(format!(
Expand Down
Loading