-
Notifications
You must be signed in to change notification settings - Fork 753
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
feat: add error stack to ErrorCode #16343
Conversation
How do I decide whether to use This PR replaces more of |
It's easy. When you want |
Use any of them is not affect the stack of ErrorCode? |
Only In practice,
In either case, the error stack is not needed. |
Are there any new tests to show the new error stack format ? |
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.
Reviewed 5 of 59 files at r1, all commit messages.
Reviewable status: 5 of 59 files reviewed, 1 unresolved discussion (waiting on @andylokandy, @sundy-li, and @zhang2014)
src/common/exception/src/exception.rs
line 104 at r1 (raw file):
pub(crate) stacks: Vec<ErrorFrame>, pub(crate) _phantom: PhantomData<C>, }
Why does ErrorCode
require a type parameter C
? Where is C
actually used?
If this type parameter serves any implicit purpose, please add a doc comment explaining it.
Code quote:
pub struct ErrorCode<C = ()> {
pub(crate) code: u16,
pub(crate) name: String,
pub(crate) display_text: String,
pub(crate) detail: String,
pub(crate) span: Span,
// cause is only used to contain an `anyhow::Error`.
// TODO: remove `cause` when we completely get rid of `anyhow::Error`.
pub(crate) cause: Option<Box<dyn std::error::Error + Sync + Send>>,
pub(crate) backtrace: Option<ErrorCodeBacktrace>,
pub(crate) stacks: Vec<ErrorFrame>,
pub(crate) _phantom: PhantomData<C>,
}
Why need to change Perhaps it is compatible?
|
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.
Reviewed 10 of 59 files at r1.
Reviewable status: 15 of 59 files reviewed, 2 unresolved discussions (waiting on @andylokandy, @sundy-li, and @zhang2014)
a discussion (no related file):
I recommend using Result
for std::result::Result
throughout our codebase. For the specialized Result<T, ErrorCode>
, consider using a different term, such as my_lib::Result
.
This is an code style change described in #15741. Since when the issue is written, I've tried multiple ways to bring Example: async fn send(addr: &str, payload: &[u8]) -> Result<(), ConnError> {
let make_error = || format!("failed to connect to {addr}");
let endpoint = conn.connect_to(addr).await.with_context(make_error)?;
endpoint.send(payload).await.with_context(make_error)?;
Ok(())
} when error occurs:
There is a problem in this code style: the developer usually just not add context where apropriate, and then just This PR has the exact same design with a slightly different name. Another question is |
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 approve this approach as it is an appropriate method to introduce error-stack when necessary.
Another question: to track all internal error stacks? If so, how would the code look? |
If you mean rendering the stacks produced by with_context at the top level, yes, it can. |
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Tests
Type of change
This change is