From b8971b8250bc810edd9f19d7525404d231c1b2df Mon Sep 17 00:00:00 2001 From: zyy17 Date: Tue, 14 May 2024 18:59:19 +0800 Subject: [PATCH] refactor: use '#[snafu(source(from()))' --- src/cmd/src/datanode.rs | 1 - src/cmd/src/error.rs | 2 +- src/cmd/src/frontend.rs | 1 - src/cmd/src/metasrv.rs | 1 - src/cmd/src/standalone.rs | 10 ++++------ src/datanode/src/error.rs | 1 + src/datanode/src/service.rs | 7 +------ src/frontend/src/error.rs | 1 + src/frontend/src/frontend.rs | 2 +- src/frontend/src/server.rs | 2 +- src/meta-srv/src/bootstrap.rs | 4 +--- src/meta-srv/src/error.rs | 1 + 12 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/cmd/src/datanode.rs b/src/cmd/src/datanode.rs index c980f7181109..c21e03499973 100644 --- a/src/cmd/src/datanode.rs +++ b/src/cmd/src/datanode.rs @@ -143,7 +143,6 @@ impl StartCommand { self.config_file.as_deref(), self.env_prefix.as_ref(), ) - .map_err(Box::new) .context(LoadLayeredConfigSnafu)?, )?, ))) diff --git a/src/cmd/src/error.rs b/src/cmd/src/error.rs index af9bdaf2b07d..0e1fec26dfa4 100644 --- a/src/cmd/src/error.rs +++ b/src/cmd/src/error.rs @@ -208,7 +208,7 @@ pub enum Error { #[snafu(display("Failed to load layered config"))] LoadLayeredConfig { - #[snafu(source)] + #[snafu(source(from(common_config::error::Error, Box::new)))] source: Box, #[snafu(implicit)] location: Location, diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index 654e4130e82c..4297553304f8 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -163,7 +163,6 @@ impl StartCommand { self.config_file.as_deref(), self.env_prefix.as_ref(), ) - .map_err(Box::new) .context(LoadLayeredConfigSnafu)?, )?, ))) diff --git a/src/cmd/src/metasrv.rs b/src/cmd/src/metasrv.rs index 4de723aa53f5..f6e7a0c3c472 100644 --- a/src/cmd/src/metasrv.rs +++ b/src/cmd/src/metasrv.rs @@ -136,7 +136,6 @@ impl StartCommand { self.config_file.as_deref(), self.env_prefix.as_ref(), ) - .map_err(Box::new) .context(LoadLayeredConfigSnafu)?, )?, ))) diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index df95868fa979..ff810ead5d41 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -22,9 +22,8 @@ use cache::{ }; use catalog::kvbackend::KvBackendCatalogManager; use clap::Parser; -use common_config::Configurable; use common_catalog::consts::{MIN_USER_FLOW_ID, MIN_USER_TABLE_ID}; -use common_config::{metadata_store_dir, KvBackendConfig}; +use common_config::{metadata_store_dir, Configurable, KvBackendConfig}; use common_meta::cache::LayeredCacheRegistryBuilder; use common_meta::cache_invalidator::CacheInvalidatorRef; use common_meta::ddl::flow_meta::{FlowMetadataAllocator, FlowMetadataAllocatorRef}; @@ -64,9 +63,9 @@ use snafu::{OptionExt, ResultExt}; use crate::error::{ BuildCacheRegistrySnafu, CacheRequiredSnafu, CreateDirSnafu, IllegalConfigSnafu, - InitDdlManagerSnafu, InitMetadataSnafu, InitTimezoneSnafu, Result, ShutdownDatanodeSnafu, - ShutdownFrontendSnafu, StartDatanodeSnafu, StartFrontendSnafu, StartProcedureManagerSnafu, - StartWalOptionsAllocatorSnafu, StopProcedureManagerSnafu,LoadLayeredConfigSnafu + InitDdlManagerSnafu, InitMetadataSnafu, InitTimezoneSnafu, LoadLayeredConfigSnafu, Result, + ShutdownDatanodeSnafu, ShutdownFrontendSnafu, StartDatanodeSnafu, StartFrontendSnafu, + StartProcedureManagerSnafu, StartWalOptionsAllocatorSnafu, StopProcedureManagerSnafu, }; use crate::options::{GlobalOptions, Options}; use crate::App; @@ -295,7 +294,6 @@ impl StartCommand { self.config_file.as_deref(), self.env_prefix.as_ref(), ) - .map_err(Box::new) .context(LoadLayeredConfigSnafu)?, )?, ))) diff --git a/src/datanode/src/error.rs b/src/datanode/src/error.rs index f62c4604b41b..ec3bccceeb41 100644 --- a/src/datanode/src/error.rs +++ b/src/datanode/src/error.rs @@ -364,6 +364,7 @@ pub enum Error { TomlFormat { #[snafu(implicit)] location: Location, + #[snafu(source(from(common_config::error::Error, Box::new)))] source: Box, }, } diff --git a/src/datanode/src/service.rs b/src/datanode/src/service.rs index 931a9fa85f30..dccacf6813f0 100644 --- a/src/datanode/src/service.rs +++ b/src/datanode/src/service.rs @@ -76,12 +76,7 @@ impl<'a> DatanodeServiceBuilder<'a> { if self.enable_http_service { let http_server = HttpServerBuilder::new(self.opts.http.clone()) .with_metrics_handler(MetricsHandler) - .with_greptime_config_options( - self.opts - .to_toml() - .map_err(Box::new) - .context(TomlFormatSnafu)?, - ) + .with_greptime_config_options(self.opts.to_toml().context(TomlFormatSnafu)?) .build(); let addr: SocketAddr = self.opts.http.addr.parse().context(ParseAddrSnafu { addr: &self.opts.http.addr, diff --git a/src/frontend/src/error.rs b/src/frontend/src/error.rs index d92a3c38ccaf..f7bd62081fbf 100644 --- a/src/frontend/src/error.rs +++ b/src/frontend/src/error.rs @@ -345,6 +345,7 @@ pub enum Error { TomlFormat { #[snafu(implicit)] location: Location, + #[snafu(source(from(common_config::error::Error, Box::new)))] source: Box, }, diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs index b499a833da14..f0dfac1c7d5c 100644 --- a/src/frontend/src/frontend.rs +++ b/src/frontend/src/frontend.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use common_telemetry::logging::{LoggingOptions, TracingOptions}; use common_config::config::Configurable; +use common_telemetry::logging::{LoggingOptions, TracingOptions}; use meta_client::MetaClientOptions; use serde::{Deserialize, Serialize}; use servers::export_metrics::ExportMetricsOption; diff --git a/src/frontend/src/server.rs b/src/frontend/src/server.rs index 4218cc57e4c8..2309b027349c 100644 --- a/src/frontend/src/server.rs +++ b/src/frontend/src/server.rs @@ -172,7 +172,7 @@ where let opts = self.opts.clone(); let instance = self.instance.clone(); - let toml = opts.to_toml().map_err(Box::new).context(TomlFormatSnafu)?; + let toml = opts.to_toml().context(TomlFormatSnafu)?; let opts: FrontendOptions = opts.into(); let handlers = ServerHandlers::default(); diff --git a/src/meta-srv/src/bootstrap.rs b/src/meta-srv/src/bootstrap.rs index b50ebc875c1e..f5ca9174eace 100644 --- a/src/meta-srv/src/bootstrap.rs +++ b/src/meta-srv/src/bootstrap.rs @@ -74,9 +74,7 @@ impl MetasrvInstance { let httpsrv = Arc::new( HttpServerBuilder::new(opts.http.clone()) .with_metrics_handler(MetricsHandler) - .with_greptime_config_options( - opts.to_toml().map_err(Box::new).context(TomlFormatSnafu)?, - ) + .with_greptime_config_options(opts.to_toml().context(TomlFormatSnafu)?) .build(), ); // put metasrv into plugins for later use diff --git a/src/meta-srv/src/error.rs b/src/meta-srv/src/error.rs index 167398cc562c..e598a956d8dc 100644 --- a/src/meta-srv/src/error.rs +++ b/src/meta-srv/src/error.rs @@ -837,6 +837,7 @@ pub enum Error { TomlFormat { #[snafu(implicit)] location: Location, + #[snafu(source(from(common_config::error::Error, Box::new)))] source: Box, }, }