Skip to content

Commit

Permalink
macro it
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed Apr 3, 2024
1 parent c275e0e commit fcd8cb0
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions kernel/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub type DeltaResult<T, E = Error> = std::result::Result<T, E>;

#[derive(thiserror::Error, Debug)]
pub enum Error {
// This is an error that includes a backtrace. To have a particular type of error include such
// backtrace (when RUST_BACKTRACE=1), annotate the error with `#[error(transparent)]` and then
// add the error type and enum variant to the `from_with_backtrace!` macro invocation below. See
// IOError for an example.
#[error("{source}\n{backtrace}")]
Backtraced {
source: Box<Self>,
Expand All @@ -35,8 +39,8 @@ pub enum Error {
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},

#[error("IO error: {0}")]
IOError(#[from] std::io::Error),
#[error(transparent)]
IOError(std::io::Error),

#[cfg(feature = "parquet")]
#[error("Arrow error: {0}")]
Expand Down Expand Up @@ -73,8 +77,8 @@ pub enum Error {
#[error("Invalid url: {0}")]
InvalidUrl(#[from] url::ParseError),

#[error("Invalid url: {0}")]
MalformedJson(#[from] serde_json::Error),
#[error(transparent)]
MalformedJson(serde_json::Error),

#[error("No table metadata found in delta log.")]
MissingMetadata,
Expand Down Expand Up @@ -144,6 +148,23 @@ impl Error {
}
}

macro_rules! from_with_backtrace(
( $(($error_type: ty, $error_variant: ident)), * ) => {
$(
impl From<$error_type> for Error {
fn from(value: $error_type) -> Self {
Self::$error_variant(value).with_backtrace()
}
}
)*
};
);

from_with_backtrace!(
(serde_json::Error, MalformedJson),
(std::io::Error, IOError)
);

#[cfg(any(feature = "default-client", feature = "sync-client"))]
impl From<arrow_schema::ArrowError> for Error {
fn from(value: arrow_schema::ArrowError) -> Self {
Expand Down

0 comments on commit fcd8cb0

Please sign in to comment.