-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add macros for DataFusionError variants #15946
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
Conversation
46d4193 to
9ab2ef4
Compare
datafusion/common/src/error.rs
Outdated
| make_error!(internal_err, internal_datafusion_err, Internal); | ||
|
|
||
| // Exposes a macro to create `DataFusionError::IoError` with optional backtrace | ||
| make_error!(external_err, external_datafusion_err, External); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't there any current usage of this error types it to replace with macros?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @comphead, I noticed that using make_error! isn't suitable for these error variants because External and ExecutionJoin are designed to wrap original error objects, not just error messages.
Instead, I've implemented custom macros for External and ExecutionJoin errors, similar to #15796, and replaced a few use cases as examples. Should we replace all the cases?
9ab2ef4 to
dfeded6
Compare
comphead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key point of this macros is preserving backtrace which makes debugging easier if you got an error from datafusion among multiple layers of processing.
The variant below is for non string errors preserving the backtrace
#[macro_export]
macro_rules! schema_err {
($ERR:expr $(; diagnostic = $DIAG:expr)?) => {{
let err = $crate::error::DataFusionError::SchemaError(
$ERR,
Box::new(Some($crate::error::DataFusionError::get_back_trace())),
);
$(
let err = err.with_diagnostic($DIAG);
)?
Err(err)
}
};
}
|
@comphead Thank you for your review. You're right - my current implementation doesn't preserve backtraces. To preserve backtraces, I think there are two options:
Do you think which approach is better, or would you recommend a different solution? |
comphead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Chen-Yuan-Lai I think second option is good way to go, more over we already have similar invariants
/// Error returned by arrow.
///
/// 2nd argument is for optional backtrace
ArrowError(ArrowError, Option<String>),
86e6084 to
013a858
Compare
Summary of this change
|
datafusion/common/src/error.rs
Outdated
| where | ||
| E: Into<GenericError>, | ||
| { | ||
| err.into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I'm not sure about if this method is needed, can we just inline it into the macros where it is being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but to prevent the compiler from resolving the target type for e.into(), I use GenericError::from(e) to explicitly provide the target type
datafusion/datafusion/common/src/error.rs
Lines 926 to 930 in e030422
| let err = $crate::error::DataFusionError::External( | |
| // covert input to GenericError | |
| $crate::error::GenericError::from($CONVERTIBLE_TO_ERR), | |
| Some($crate::error::DataFusionError::get_back_trace()) | |
| ); |
comphead
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @Chen-Yuan-Lai I think we really close to it
51fb865 to
e030422
Compare
| return Err(DataFusionError::External( | ||
| "PrintFormat::Table is not implemented".to_string().into(), | ||
| )); | ||
| return external_err!("PrintFormat::Table is not implemented"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have noticed the lack of this macro recently too -- thank you for adding it 🙏
|
Thank you for this PR @Chen-Yuan-Lai and @comphead -- very nice I am a little worried about changing the DataFusionError variant as it which will be a disruptive downstream change (users have to update all match statements that currently match on Rather than change the So keep Or something like that |
e030422 to
7d377dc
Compare
…tionJoin and External errors
… and ExecutionJoin errors
…macro across the codebase
…prove error messages
…ternal error macros
…n_err macro to convert input directly to GenericError
7d377dc to
55770ca
Compare
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
Which issue does this PR close?
Rationale for this change
What changes are included in this PR?
As #15491 says, add two macros for
Moreover, the macro for
ResourcesExhaustedalready existed, so we don't need to add it in the PRAre these changes tested?
Are there any user-facing changes?