-
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
Changes from 6 commits
64aad6c
bb34b5e
2b32ba6
f62b71b
ab4e797
1ec2c89
3c370f8
fa9eae6
f16fd49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ use memcomparable::Error as MemComparableError; | |
use risingwave_error::tonic::{ToTonicStatus, TonicStatusWrapper}; | ||
use risingwave_pb::PbFieldNotFound; | ||
use thiserror::Error; | ||
use thiserror_ext::Macro; | ||
use tokio::task::JoinError; | ||
|
||
use crate::array::ArrayError; | ||
|
@@ -36,7 +37,7 @@ pub type BoxedError = Box<dyn Error>; | |
|
||
pub use anyhow::anyhow as anyhow_error; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
#[derive(Debug, Clone, Copy, Default)] | ||
pub struct TrackingIssue(Option<u32>); | ||
|
||
impl TrackingIssue { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
#[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 commentThe 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 If the structure is private, then BTW, is there any way to automatically derive this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find a way. 😕 Calling |
||
pub struct NotImplemented { | ||
#[message] | ||
pub feature: String, | ||
pub issue: TrackingIssue, | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ErrorCode { | ||
#[error("internal error: {0}")] | ||
|
@@ -87,8 +97,8 @@ pub enum ErrorCode { | |
#[backtrace] | ||
BoxedError, | ||
), | ||
#[error("Feature is not yet implemented: {0}\n{1}")] | ||
NotImplemented(String, TrackingIssue), | ||
#[error(transparent)] | ||
NotImplemented(#[from] NotImplemented), | ||
// Tips: Use this only if it's intended to reject the query | ||
#[error("Not supported: {0}\nHINT: {1}")] | ||
NotSupported(String, String), | ||
|
@@ -200,6 +210,13 @@ pub enum ErrorCode { | |
), | ||
} | ||
|
||
// TODO(error-handling): automatically generate this impl. | ||
impl From<NotImplemented> for RwError { | ||
fn from(value: NotImplemented) -> Self { | ||
ErrorCode::from(value).into() | ||
} | ||
} | ||
|
||
pub fn internal_error(msg: impl Into<String>) -> RwError { | ||
ErrorCode::InternalError(msg.into()).into() | ||
} | ||
|
@@ -479,14 +496,8 @@ macro_rules! ensure_eq { | |
|
||
#[macro_export] | ||
macro_rules! bail { | ||
($msg:literal $(,)?) => { | ||
return Err($crate::error::anyhow_error!($msg).into()) | ||
}; | ||
($err:expr $(,)?) => { | ||
return Err($crate::error::anyhow_error!($err).into()) | ||
}; | ||
($fmt:expr, $($arg:tt)*) => { | ||
return Err($crate::error::anyhow_error!($fmt, $($arg)*).into()) | ||
($($arg:tt)*) => { | ||
return Err($crate::error::anyhow_error!($($arg)*).into()) | ||
}; | ||
} | ||
|
||
|
@@ -616,7 +627,7 @@ mod tests { | |
check_grpc_error(ErrorCode::TaskNotFound, Code::Internal); | ||
check_grpc_error(ErrorCode::InternalError(String::new()), Code::Internal); | ||
check_grpc_error( | ||
ErrorCode::NotImplemented(String::new(), None.into()), | ||
ErrorCode::NotImplemented(not_implemented!("test")), | ||
Code::Internal, | ||
); | ||
} | ||
|
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).