-
Notifications
You must be signed in to change notification settings - Fork 590
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
refactor(error): simplify leaf error instantiation #13627
Conversation
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
5a79c16
to
f62b71b
Compare
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
statement error | ||
set rw_implicit_flush to maybe; | ||
---- | ||
db error: ERROR: Failed to run the query | ||
|
||
Caused by these errors (recent errors listed first): | ||
1: Failed to get/set session config | ||
2: Invalid value `maybe` for `rw_implicit_flush` | ||
3: provided string was not `true` or `false` |
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.
Forget to add tests in last PR (#13588).
@@ -70,6 +71,15 @@ impl Display for TrackingIssue { | |||
} | |||
} | |||
|
|||
#[derive(Error, Debug, Macro)] | |||
#[error("Feature is not yet implemented: {feature}. {issue}")] | |||
#[thiserror_ext(macro(path = "crate::error"))] |
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 is because we want the qualified name when calling from other crates to avoid importing the structure itself. So we generate the path $crate::error::
before the type name.
If the structure is private, then path
is not necessary.
BTW, is there any way to automatically derive this?
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.
Does module_path!()
work?
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 didn't find a way. 😕 Calling module_path
in the proc macro body won't work as we will get the module path of the proc macro crate.
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.
LGTM!
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.
Why do we need to generate macros, instead of methods?
@@ -70,6 +71,15 @@ impl Display for TrackingIssue { | |||
} | |||
} | |||
|
|||
#[derive(Error, Debug, Macro)] |
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.
Macro
isn't a very cool name 😕
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.
Do you have any proposals? 😢 It's not stable, so feel free to change.
Because we want tons of sugars! With macro, we can achieve...
Actually the philosophy is picked from |
Signed-off-by: Bugen Zhao <[email protected]>
But I feel it might be too sweet. Different from I'm wondering would it be enough to have sth like methods accepting Anyway, it's a matter of taste. I do not even hold strong opinions to block this PR. Feel free to proceed in any way you like! |
Signed-off-by: Bugen Zhao <[email protected]>
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.
Do we really need bail_not_implemented
? It does simplify our code a lot, but I'm afraid the code can finally become hard to read if number of such macros gradually increase. The key problem is that it involves implicit control flow, although when there is only one bail
, it looks clear.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #13627 +/- ##
==========================================
- Coverage 68.24% 68.23% -0.02%
==========================================
Files 1521 1521
Lines 261722 261488 -234
==========================================
- Hits 178620 178417 -203
+ Misses 83102 83071 -31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
In this PR, we take the
NotImplemented
error as an example.Instead of writing something like...
...simply write...
to construct a
NotImplemented
error variant then convert and bail out.If the
issue
is not applicable, omitting the field also works. This implies<Option<TrackingIssue> as Default>::default()
.Because we want tons of sugars! With macro, we can achieve...
format
and implicit conversion (even forBox<str>
messages).Err(...).into()
everywhere.Actually the philosophy is picked from
anyhow
. To construct a leaf error withanyhow
, we useanyhow!(<format_args>)
and bail out withbail!(..)
.The interesting part is that the macro
[bail_]not_implemented
itself is generated by the proc-macrothiserror_ext::Macro
!risingwave/src/common/src/error.rs
Lines 73 to 80 in 5a79c16
The
#[message]
attribute here indicates which field should be formatted into. By the way, the macro is also applicable on enum variants.This means that the convenience for constructing a new error can be scaled out easily in the future.
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.