Skip to content

Commit

Permalink
refactor: use '#[snafu(source(from()))'
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy17 committed May 14, 2024
1 parent f54c812 commit b8971b8
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/cmd/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl StartCommand {
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.map_err(Box::new)
.context(LoadLayeredConfigSnafu)?,
)?,
)))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<common_config::error::Error>,
#[snafu(implicit)]
location: Location,
Expand Down
1 change: 0 additions & 1 deletion src/cmd/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ impl StartCommand {
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.map_err(Box::new)
.context(LoadLayeredConfigSnafu)?,
)?,
)))
Expand Down
1 change: 0 additions & 1 deletion src/cmd/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl StartCommand {
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.map_err(Box::new)
.context(LoadLayeredConfigSnafu)?,
)?,
)))
Expand Down
10 changes: 4 additions & 6 deletions src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -295,7 +294,6 @@ impl StartCommand {
self.config_file.as_deref(),
self.env_prefix.as_ref(),
)
.map_err(Box::new)
.context(LoadLayeredConfigSnafu)?,
)?,
)))
Expand Down
1 change: 1 addition & 0 deletions src/datanode/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ pub enum Error {
TomlFormat {
#[snafu(implicit)]
location: Location,
#[snafu(source(from(common_config::error::Error, Box::new)))]
source: Box<common_config::error::Error>,
},
}
Expand Down
7 changes: 1 addition & 6 deletions src/datanode/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ pub enum Error {
TomlFormat {
#[snafu(implicit)]
location: Location,
#[snafu(source(from(common_config::error::Error, Box::new)))]
source: Box<common_config::error::Error>,
},

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/meta-srv/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/meta-srv/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ pub enum Error {
TomlFormat {
#[snafu(implicit)]
location: Location,
#[snafu(source(from(common_config::error::Error, Box::new)))]
source: Box<common_config::error::Error>,
},
}
Expand Down

0 comments on commit b8971b8

Please sign in to comment.