Skip to content
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

fix: refine error prompting #4227

Merged
merged 4 commits into from
Aug 1, 2022
Merged

fix: refine error prompting #4227

merged 4 commits into from
Aug 1, 2022

Conversation

neverchanje
Copy link
Contributor

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

This PR refined some errors to be more user-friendly.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

@github-actions github-actions bot added the type/fix Bug fix label Jul 27, 2022
@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #4227 (d9bfbf8) into main (e31b607) will increase coverage by 0.01%.
The diff coverage is 30.76%.

@@            Coverage Diff             @@
##             main    #4227      +/-   ##
==========================================
+ Coverage   74.32%   74.33%   +0.01%     
==========================================
  Files         844      844              
  Lines      122378   122336      -42     
==========================================
- Hits        90956    90941      -15     
+ Misses      31422    31395      -27     
Flag Coverage Δ
rust 74.33% <30.76%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/connector/src/macros.rs 60.86% <ø> (ø)
src/connector/src/source/base.rs 59.09% <ø> (ø)
...rc/connector/src/source/kafka/enumerator/client.rs 0.00% <0.00%> (ø)
src/common/src/error.rs 70.04% <66.66%> (+5.42%) ⬆️
src/source/src/parser/common.rs 77.77% <66.66%> (-1.64%) ⬇️
src/common/src/types/ordered_float.rs 29.10% <0.00%> (+0.19%) ⬆️
src/meta/src/rpc/server.rs 78.60% <0.00%> (+0.21%) ⬆️
src/connector/src/source/filesystem/file_common.rs 80.80% <0.00%> (+0.44%) ⬆️
src/meta/src/manager/id.rs 95.10% <0.00%> (+0.54%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Comment on lines -194 to -204
_ => {
let bytes = {
let status = err.to_status();
let mut bytes = Vec::<u8>::with_capacity(status.encoded_len());
status.encode(&mut bytes).expect("Failed to encode status.");
bytes
};
let mut header = MetadataMap::new();
header.insert_bin(RW_ERROR_GRPC_HEADER, MetadataValue::from_bytes(&bytes));
tonic::Status::with_metadata(Code::Internal, err.to_string(), header)
}
Copy link
Member

@xxchan xxchan Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep it, and decode in impl From<tonic::Status> for RwError, just like the legacy java fe https://github.com/singularity-data/risingwave-legacy/pull/1948/files#diff-5aee0d702428cdd3f280945a3ba0c18533c152d30427dd9b3d4d369b4e50f710R54-R65

impl From<tonic::Status> for RwError {
    fn from(err: tonic::Status) -> Self {
        if let Some(err) = err.metadata().get_bin(RW_ERROR_GRPC_HEADER) &&
            let Ok(err) = err.to_bytes() && 
            let Ok(status) = Status::decode(err) {
			// still need to be improved here
            return ErrorCode::InternalError(status.message).into();
        }
		
		...

To be more specific, we should use Status proto stored in grpc status metadata, instead of grpc error codes. In this way, we can have more organized custom error codes and error messages in the future. cc @liurenjie1024
https://github.com/singularity-data/risingwave/blob/9d8b7d2bd7b9041f3272aed081d7cc99a36a968c/proto/common.proto#L7-L13

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(BTW, I just removed #![expect(dead_code)], so after merging main clippy will fail 🥸

Copy link
Contributor Author

@neverchanje neverchanje Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl RwError {
    fn to_status(&self) -> Status {
        Status {
            code: self.inner.get_code() as i32,
            message: self.to_string(), // Simply discard the details and encode itself to string.
        }
    }

Actually, we didn't encode the enum ErrorCode into a protobuf struct that can be decoded as it completely was, instead, the ErrorCode as well as its details, was only encoded as a plain string.

Hence, a ConnectorError, after being transported via grpc, if decoded strictly according to the code, will become:

connector error: connector error: xxxx

According to what we've currently implemented, it will be like internal error: connector error: xxx. So such a decoding phase won't take effect anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the current implementation doesn't make full sense, but the idea might be good in the future. Anyway I think it needs to be carefully re-designed, so I think it's also ok to remove it and KISS for now.

@mergify mergify bot merged commit b4ba2ed into main Aug 1, 2022
@mergify mergify bot deleted the wt-time branch August 1, 2022 05:33
nasnoisaac pushed a commit to nasnoisaac/risingwave that referenced this pull request Aug 9, 2022
* fix: refine error prompting

* fix clippy

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants