From bb34b5ed1f4bb03c165ede477fc36cae7231a39a Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Fri, 24 Nov 2023 02:01:05 +0800 Subject: [PATCH] use derived ctor macro and bail macros Signed-off-by: Bugen Zhao --- Cargo.lock | 7 ++--- Cargo.toml | 3 +- src/common/src/error.rs | 61 ++++++----------------------------------- 3 files changed, 13 insertions(+), 58 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ce437599471b..dbde44581073 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10209,8 +10209,7 @@ dependencies = [ [[package]] name = "thiserror-ext" version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e0feae8c8aff1b65f0bca5b24fe2b6e2331e03cd7c6daa681e43a8055f92f6" +source = "git+https://github.com/risingwavelabs/thiserror-ext.git?rev=0912af#0912af4c8300d014e16d884b0c1fede865db0d28" dependencies = [ "thiserror", "thiserror-ext-derive", @@ -10219,9 +10218,9 @@ dependencies = [ [[package]] name = "thiserror-ext-derive" version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e32482e53bca3d022bdee662ea7d568835e0eb8a86ab410946104657e9e1b5b5" +source = "git+https://github.com/risingwavelabs/thiserror-ext.git?rev=0912af#0912af4c8300d014e16d884b0c1fede865db0d28" dependencies = [ + "either", "proc-macro2", "quote", "syn 2.0.37", diff --git a/Cargo.toml b/Cargo.toml index e99ba6030ebb..ac35def300b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,8 @@ arrow-flight = "49" arrow-select = "49" arrow-ord = "49" arrow-row = "49" -thiserror-ext = "0.0.7" +# thiserror-ext = "0.0.7" +thiserror-ext = { git = "https://github.com/risingwavelabs/thiserror-ext.git", rev = "0912af" } tikv-jemalloc-ctl = { git = "https://github.com/risingwavelabs/jemallocator.git", rev = "64a2d9" } tikv-jemallocator = { git = "https://github.com/risingwavelabs/jemallocator.git", features = [ "profiling", diff --git a/src/common/src/error.rs b/src/common/src/error.rs index 3ab8726e3289..ee802e5817a8 100644 --- a/src/common/src/error.rs +++ b/src/common/src/error.rs @@ -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; pub use anyhow::anyhow as anyhow_error; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub struct TrackingIssue(Option); impl TrackingIssue { @@ -70,59 +71,13 @@ impl Display for TrackingIssue { } } -#[derive(Error, Debug)] -#[error("Feature is not yet implemented: {feature}. {tracking_issue}")] +#[derive(Error, Debug, Macro)] +#[error("Feature is not yet implemented: {feature}. {issue}")] +#[thiserror_ext(macro(path = "crate::error"))] pub struct NotImplemented { + #[message] pub feature: String, - pub tracking_issue: TrackingIssue, -} - -impl From for NotImplemented -where - S: Into, -{ - fn from(feature: S) -> Self { - Self::new(feature) - } -} - -impl NotImplemented { - pub fn new(feature: impl Into) -> Self { - Self::with_tracking_issue(feature, TrackingIssue::none()) - } - - pub fn with_tracking_issue( - feature: impl Into, - tracking_issue: impl Into, - ) -> Self { - Self { - feature: feature.into(), - tracking_issue: tracking_issue.into(), - } - } -} - -#[macro_export] -macro_rules! not_implemented { - (issue = $issue:expr, $($arg:tt)*) => { - $crate::error::NotImplemented::with_tracking_issue( - ::std::format!($($arg)*), - $issue, - ) - }; - ($($arg:tt)*) => { - not_implemented!(issue = None, $($arg)*) - }; -} - -#[macro_export(local_inner_macros)] -macro_rules! bail_not_implemented { - (issue = $issue:expr, $($arg:tt)*) => { - return Err(not_implemented!(issue = $issue, $($arg)*).into()) - }; - ($($arg:tt)*) => { - bail_not_implemented!(issue = None, $($arg)*) - }; + pub issue: TrackingIssue, } #[derive(Error, Debug)] @@ -672,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(NotImplemented::new("test")), + ErrorCode::NotImplemented(not_implemented!("test")), Code::Internal, ); }