From cca63a0983363526418292ccbee83b9b041d5040 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Wed, 29 Nov 2023 15:57:43 +0800 Subject: [PATCH] cleanup Signed-off-by: Bugen Zhao --- src/batch/clippy.toml | 2 -- src/common/src/error.rs | 4 ---- src/frontend/src/binder/relation/mod.rs | 8 +++----- src/source/src/connector_source.rs | 11 +++++------ src/source/src/fs_connector_source.rs | 8 +++----- src/stream/clippy.toml | 3 --- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/batch/clippy.toml b/src/batch/clippy.toml index e128bc11b1f53..aeb91fb713fb1 100644 --- a/src/batch/clippy.toml +++ b/src/batch/clippy.toml @@ -1,6 +1,4 @@ disallowed-methods = [ - { path = "risingwave_common::error::internal_err", reason = "Please use per-crate error type instead." }, - { path = "risingwave_common::error::internal_error", reason = "Please use per-crate error type instead." }, ] disallowed-types = [ diff --git a/src/common/src/error.rs b/src/common/src/error.rs index d300cf8f06474..ce99b3bb7a39d 100644 --- a/src/common/src/error.rs +++ b/src/common/src/error.rs @@ -212,10 +212,6 @@ pub enum ErrorCode { ), } -pub fn internal_error(msg: impl Into) -> RwError { - ErrorCode::InternalError(msg.into()).into() -} - impl From for tonic::Status { fn from(err: RwError) -> Self { use tonic::Code; diff --git a/src/frontend/src/binder/relation/mod.rs b/src/frontend/src/binder/relation/mod.rs index 856f221ec9855..34ee66e45782a 100644 --- a/src/frontend/src/binder/relation/mod.rs +++ b/src/frontend/src/binder/relation/mod.rs @@ -16,8 +16,9 @@ use std::collections::hash_map::Entry; use std::ops::Deref; use itertools::{EitherOrBoth, Itertools}; +use risingwave_common::bail; use risingwave_common::catalog::{Field, TableId, DEFAULT_SCHEMA_NAME}; -use risingwave_common::error::{internal_error, ErrorCode, Result, RwError}; +use risingwave_common::error::{ErrorCode, Result, RwError}; use risingwave_sqlparser::ast::{ Expr as ParserExpr, FunctionArg, FunctionArgExpr, Ident, ObjectName, TableAlias, TableFactor, }; @@ -208,10 +209,7 @@ impl Binder { /// return first name in identifiers, must have only one name. fn resolve_single_name(mut identifiers: Vec, ident_desc: &str) -> Result { if identifiers.len() > 1 { - return Err(internal_error(format!( - "{} must contain 1 argument", - ident_desc - ))); + bail!("{} must contain 1 argument", ident_desc); } let name = identifiers.pop().unwrap().real_value(); diff --git a/src/source/src/connector_source.rs b/src/source/src/connector_source.rs index e0a3ac62276d1..a336719503b00 100644 --- a/src/source/src/connector_source.rs +++ b/src/source/src/connector_source.rs @@ -15,14 +15,16 @@ use std::collections::HashMap; use std::sync::Arc; +use anyhow::anyhow; use futures::future::try_join_all; use futures::stream::pending; use futures::StreamExt; use futures_async_stream::try_stream; use itertools::Itertools; +use risingwave_common::bail; use risingwave_common::catalog::ColumnId; use risingwave_common::error::ErrorCode::ConnectorError; -use risingwave_common::error::{internal_error, Result, RwError}; +use risingwave_common::error::{Result, RwError}; use risingwave_common::util::select_all; use risingwave_connector::dispatch_source_prop; use risingwave_connector::parser::{CommonParserConfig, ParserConfig, SpecificParserConfig}; @@ -78,10 +80,7 @@ impl ConnectorSource { .iter() .find(|c| c.column_id == *id) .ok_or_else(|| { - internal_error(format!( - "Failed to find column id: {} in source: {:?}", - id, self - )) + anyhow!("Failed to find column id: {} in source: {:?}", id, self).into() }) .map(|col| col.clone()) }) @@ -94,7 +93,7 @@ impl ConnectorSource { ConnectorProperties::S3(prop) => { S3SplitEnumerator::new(*prop, Arc::new(SourceEnumeratorContext::default())).await? } - other => return Err(internal_error(format!("Unsupported source: {:?}", other))), + other => bail!("Unsupported source: {:?}", other), }; Ok(build_fs_list_stream( diff --git a/src/source/src/fs_connector_source.rs b/src/source/src/fs_connector_source.rs index 671f5b99c5bae..7ef5ba67ac70c 100644 --- a/src/source/src/fs_connector_source.rs +++ b/src/source/src/fs_connector_source.rs @@ -17,11 +17,12 @@ use std::collections::HashMap; use std::sync::Arc; +use anyhow::anyhow; use futures::stream::pending; use futures::StreamExt; use risingwave_common::catalog::ColumnId; use risingwave_common::error::ErrorCode::ConnectorError; -use risingwave_common::error::{internal_error, Result}; +use risingwave_common::error::Result; use risingwave_connector::dispatch_source_prop; use risingwave_connector::parser::{CommonParserConfig, ParserConfig, SpecificParserConfig}; use risingwave_connector::source::{ @@ -68,10 +69,7 @@ impl FsConnectorSource { .iter() .find(|c| c.column_id == *id) .ok_or_else(|| { - internal_error(format!( - "Failed to find column id: {} in source: {:?}", - id, self - )) + anyhow!("Failed to find column id: {} in source: {:?}", id, self).into() }) .map(|col| col.clone()) }) diff --git a/src/stream/clippy.toml b/src/stream/clippy.toml index 340bd5007d09b..dd26a976e1ab1 100644 --- a/src/stream/clippy.toml +++ b/src/stream/clippy.toml @@ -5,9 +5,6 @@ disallowed-methods = [ { path = "risingwave_expr::expr::build_func", reason = "Expressions in streaming must be in non-strict mode. Please use `build_func_non_strict` instead." }, { path = "risingwave_expr::expr::Expression::eval", reason = "Please use `NonStrictExpression::eval_infallible` instead." }, { path = "risingwave_expr::expr::Expression::eval_row", reason = "Please use `NonStrictExpression::eval_row_infallible` instead." }, - - { path = "risingwave_common::error::internal_err", reason = "Please use per-crate error type instead." }, - { path = "risingwave_common::error::internal_error", reason = "Please use per-crate error type instead." }, ] disallowed-types = [