-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore: Finish refactor with assert_or_internal_err!()
#18790
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
chore: Finish refactor with assert_or_internal_err!()
#18790
Conversation
datafusion/common/src/scalar/mod.rs
Outdated
| let validation = validate_decimal_precision_and_scale::<Decimal32Type>( | ||
| *precision, *scale, | ||
| ) { | ||
| return _internal_err!("Invalid precision and scale {err}"); | ||
| } | ||
| if *scale < 0 { | ||
| return _internal_err!("Negative scale is not supported"); | ||
| } | ||
| ); | ||
| assert_or_internal_err!( | ||
| validation.is_ok(), | ||
| "Invalid precision and scale {}", | ||
| validation.unwrap_err() | ||
| ); |
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.
Seems more appropriate to do a map_err here? (Same for below)
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.
Good point. Updated in 09c15ee
| assert_or_internal_err!( | ||
| union.inputs.len() >= 2, | ||
| "Protobuf deserialization error, Union was require at least two input." | ||
| ); |
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.
This should technically be an exec error I guess?
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.
It depends I think. For SQL/Dataframe APIs, this should be an internal error, however for low level rust APIs, technically you can construct such plan and make it an execution error. So I slightly prefer to leave it as is.
| assert_eq_or_internal_err!( | ||
| (iv.months, iv.days, iv.nanoseconds), | ||
| (0, 0, 0), | ||
| "row {i}: expected (0,0,0), got ({},{},{})", |
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.
nit: assert_eq_or_internal_err() already prints the left and right values (
datafusion/datafusion/common/src/error.rs
Line 838 in 0304cda
| "Assertion failed: {} == {} (left: {:?}, right: {:?}): {}", |
| assert_eq_or_internal_err!( | ||
| (iv.months, iv.days, iv.nanoseconds), | ||
| (0, 0, 0), | ||
| "expected scalar 0s, got ({},{},{})", |
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.
Same here
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#18613 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> apache#18613 is almost finished, I searched the codebase and refactor all the remaining patterns in this PR. Such assertion macros have been scattered to the codebase, and I have also added some error handling doc in apache#18762, so later we can follow this pattern and continue adopting those macros. ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> --------- Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
Which issue does this PR close?
assert_or_internal_err!()across the codebase #18613Rationale for this change
#18613 is almost finished, I searched the codebase and refactor all the remaining patterns in this PR.
Such assertion macros have been scattered to the codebase, and I have also added some error handling doc in #18762, so later we can follow this pattern and continue adopting those macros.
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?