diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 2c86291ffcb5..5100b89754d9 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -616,8 +616,8 @@ jobs: with: # Shares across multiple jobs shared-key: "check-rust-fmt" - - name: Run cargo fmt - run: cargo fmt --all -- --check + - name: Check format + run: make fmt-check clippy: name: Clippy diff --git a/Makefile b/Makefile index ec1e394c5a13..acc2a731267c 100644 --- a/Makefile +++ b/Makefile @@ -191,6 +191,7 @@ fix-clippy: ## Fix clippy violations. .PHONY: fmt-check fmt-check: ## Check code format. cargo fmt --all -- --check + python3 scripts/check-snafu.py .PHONY: start-etcd start-etcd: ## Start single node etcd for testing purpose. diff --git a/scripts/check-snafu.py b/scripts/check-snafu.py new file mode 100644 index 000000000000..d44edfeb8c45 --- /dev/null +++ b/scripts/check-snafu.py @@ -0,0 +1,69 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import re + + +def find_rust_files(directory): + error_files = [] + other_rust_files = [] + for root, _, files in os.walk(directory): + for file in files: + if file == "error.rs": + error_files.append(os.path.join(root, file)) + elif file.endswith(".rs"): + other_rust_files.append(os.path.join(root, file)) + return error_files, other_rust_files + + +def extract_branch_names(file_content): + pattern = re.compile(r"#\[snafu\(display\([^\)]*\)\)\]\s*(\w+)\s*\{") + return pattern.findall(file_content) + + +def check_snafu_in_files(branch_name, rust_files): + branch_name_snafu = f"{branch_name}Snafu" + for rust_file in rust_files: + with open(rust_file, "r") as file: + content = file.read() + if branch_name_snafu in content: + return True + return False + + +def main(): + error_files, other_rust_files = find_rust_files(".") + branch_names = [] + + for error_file in error_files: + with open(error_file, "r") as file: + content = file.read() + branch_names.extend(extract_branch_names(content)) + + unused_snafu = [ + branch_name + for branch_name in branch_names + if not check_snafu_in_files(branch_name, other_rust_files) + ] + + for name in unused_snafu: + print(name) + + if unused_snafu: + raise SystemExit(1) + + +if __name__ == "__main__": + main() diff --git a/src/auth/src/error.rs b/src/auth/src/error.rs index 281c45234d4b..23c5f0d66cb9 100644 --- a/src/auth/src/error.rs +++ b/src/auth/src/error.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use common_error::ext::{BoxedError, ErrorExt}; +use common_error::ext::ErrorExt; use common_error::status_code::StatusCode; use common_macro::stack_trace_debug; use snafu::{Location, Snafu}; @@ -38,14 +38,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Authentication source failure"))] - AuthBackend { - #[snafu(implicit)] - location: Location, - #[snafu(source)] - source: BoxedError, - }, - #[snafu(display("User not found, username: {}", username))] UserNotFound { username: String }, @@ -89,7 +81,6 @@ impl ErrorExt for Error { Error::FileWatch { .. } => StatusCode::InvalidArguments, Error::InternalState { .. } => StatusCode::Unexpected, Error::Io { .. } => StatusCode::StorageUnavailable, - Error::AuthBackend { .. } => StatusCode::Internal, Error::UserNotFound { .. } => StatusCode::UserNotFound, Error::UnsupportedPasswordType { .. } => StatusCode::UnsupportedPasswordType, diff --git a/src/auth/tests/mod.rs b/src/auth/tests/mod.rs index cef1599c5b28..65db96a13fe1 100644 --- a/src/auth/tests/mod.rs +++ b/src/auth/tests/mod.rs @@ -18,6 +18,7 @@ use std::sync::Arc; use api::v1::greptime_request::Request; use auth::error::Error::InternalState; +use auth::error::InternalStateSnafu; use auth::{PermissionChecker, PermissionCheckerRef, PermissionReq, PermissionResp, UserInfoRef}; use sql::statements::show::{ShowDatabases, ShowKind}; use sql::statements::statement::Statement; @@ -33,9 +34,10 @@ impl PermissionChecker for DummyPermissionChecker { match req { PermissionReq::GrpcRequest(_) => Ok(PermissionResp::Allow), PermissionReq::SqlStatement(_) => Ok(PermissionResp::Reject), - _ => Err(InternalState { + _ => InternalStateSnafu { msg: "testing".to_string(), - }), + } + .fail(), } } } diff --git a/src/catalog/src/error.rs b/src/catalog/src/error.rs index fa4b469cce52..d44a5b768391 100644 --- a/src/catalog/src/error.rs +++ b/src/catalog/src/error.rs @@ -97,13 +97,6 @@ pub enum Error { source: table::error::Error, }, - #[snafu(display("System catalog is not valid: {}", msg))] - SystemCatalog { - msg: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Cannot find catalog by name: {}", catalog_name))] CatalogNotFound { catalog_name: String, @@ -186,13 +179,6 @@ pub enum Error { source: common_query::error::Error, }, - #[snafu(display("Failed to perform metasrv operation"))] - Metasrv { - #[snafu(implicit)] - location: Location, - source: meta_client::error::Error, - }, - #[snafu(display("Invalid table info in catalog"))] InvalidTableInfoInCatalog { #[snafu(implicit)] @@ -288,8 +274,6 @@ impl ErrorExt for Error { Error::FlowInfoNotFound { .. } => StatusCode::FlowNotFound, - Error::SystemCatalog { .. } => StatusCode::StorageUnavailable, - Error::UpgradeWeakCatalogManagerRef { .. } => StatusCode::Internal, Error::CreateRecordBatch { source, .. } => source.status_code(), @@ -303,7 +287,6 @@ impl ErrorExt for Error { Error::CreateTable { source, .. } => source.status_code(), - Error::Metasrv { source, .. } => source.status_code(), Error::DecodePlan { source, .. } => source.status_code(), Error::InvalidTableInfoInCatalog { source, .. } => source.status_code(), @@ -338,27 +321,6 @@ mod tests { use super::*; - #[test] - pub fn test_error_status_code() { - assert_eq!( - StatusCode::TableAlreadyExists, - Error::TableExists { - table: "some_table".to_string(), - location: Location::generate(), - } - .status_code() - ); - - assert_eq!( - StatusCode::StorageUnavailable, - Error::SystemCatalog { - msg: String::default(), - location: Location::generate(), - } - .status_code() - ); - } - #[test] pub fn test_errors_to_datafusion_error() { let e: DataFusionError = Error::TableExists { diff --git a/src/catalog/src/kvbackend/client.rs b/src/catalog/src/kvbackend/client.rs index 78c11214c726..46e13d03c2aa 100644 --- a/src/catalog/src/kvbackend/client.rs +++ b/src/catalog/src/kvbackend/client.rs @@ -20,8 +20,8 @@ use std::time::Duration; use common_error::ext::BoxedError; use common_meta::cache_invalidator::KvCacheInvalidator; -use common_meta::error::Error::{CacheNotGet, GetKvCache}; -use common_meta::error::{CacheNotGetSnafu, Error, ExternalSnafu, Result}; +use common_meta::error::Error::CacheNotGet; +use common_meta::error::{CacheNotGetSnafu, Error, ExternalSnafu, GetKvCacheSnafu, Result}; use common_meta::kv_backend::{KvBackend, KvBackendRef, TxnService}; use common_meta::rpc::store::{ BatchDeleteRequest, BatchDeleteResponse, BatchGetRequest, BatchGetResponse, BatchPutRequest, @@ -282,8 +282,11 @@ impl KvBackend for CachedMetaKvBackend { _ => Err(e), }, } - .map_err(|e| GetKvCache { - err_msg: e.to_string(), + .map_err(|e| { + GetKvCacheSnafu { + err_msg: e.to_string(), + } + .build() }); // "cache.invalidate_key" and "cache.try_get_with_by_ref" are not mutually exclusive. So we need diff --git a/src/client/src/database.rs b/src/client/src/database.rs index 9ac97df63658..a6223dc4cb5a 100644 --- a/src/client/src/database.rs +++ b/src/client/src/database.rs @@ -37,7 +37,8 @@ use tonic::metadata::AsciiMetadataKey; use tonic::transport::Channel; use crate::error::{ - ConvertFlightDataSnafu, Error, IllegalFlightMessagesSnafu, InvalidAsciiSnafu, ServerSnafu, + ConvertFlightDataSnafu, Error, FlightGetSnafu, IllegalFlightMessagesSnafu, InvalidAsciiSnafu, + ServerSnafu, }; use crate::{from_grpc_response, Client, Result}; @@ -225,16 +226,18 @@ impl Database { let mut client = self.client.make_flight_client()?; - let response = client.mut_inner().do_get(request).await.map_err(|e| { + let response = client.mut_inner().do_get(request).await.or_else(|e| { let tonic_code = e.code(); let e: Error = e.into(); let code = e.status_code(); let msg = e.to_string(); - let error = Error::FlightGet { - tonic_code, - addr: client.addr().to_string(), - source: BoxedError::new(ServerSnafu { code, msg }.build()), - }; + let error = + Err(BoxedError::new(ServerSnafu { code, msg }.build())).with_context(|_| { + FlightGetSnafu { + addr: client.addr().to_string(), + tonic_code, + } + }); error!( "Failed to do Flight get, addr: {}, code: {}, source: {:?}", client.addr(), diff --git a/src/client/src/error.rs b/src/client/src/error.rs index b5aef255d4f7..47d999059822 100644 --- a/src/client/src/error.rs +++ b/src/client/src/error.rs @@ -39,13 +39,6 @@ pub enum Error { source: BoxedError, }, - #[snafu(display("Failure occurs during handling request"))] - HandleRequest { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, - #[snafu(display("Failed to convert FlightData"))] ConvertFlightData { #[snafu(implicit)] @@ -116,13 +109,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to send request with streaming: {}", err_msg))] - ClientStreaming { - err_msg: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to parse ascii string: {}", value))] InvalidAscii { value: String, @@ -138,12 +124,10 @@ impl ErrorExt for Error { match self { Error::IllegalFlightMessages { .. } | Error::MissingField { .. } - | Error::IllegalDatabaseResponse { .. } - | Error::ClientStreaming { .. } => StatusCode::Internal, + | Error::IllegalDatabaseResponse { .. } => StatusCode::Internal, Error::Server { code, .. } => *code, Error::FlightGet { source, .. } - | Error::HandleRequest { source, .. } | Error::RegionServer { source, .. } | Error::FlowServer { source, .. } => source.status_code(), Error::CreateChannel { source, .. } diff --git a/src/client/src/flow.rs b/src/client/src/flow.rs index de0d2c8b319e..0d5963f848ac 100644 --- a/src/client/src/flow.rs +++ b/src/client/src/flow.rs @@ -16,9 +16,9 @@ use api::v1::flow::{FlowRequest, FlowResponse}; use api::v1::region::InsertRequests; use common_error::ext::BoxedError; use common_meta::node_manager::Flownode; -use snafu::{location, ResultExt}; +use snafu::ResultExt; -use crate::error::Result; +use crate::error::{FlowServerSnafu, Result}; use crate::Client; #[derive(Debug)] @@ -57,15 +57,10 @@ impl FlowRequester { let response = client .handle_create_remove(request) .await - .map_err(|e| { + .or_else(|e| { let code = e.code(); let err: crate::error::Error = e.into(); - crate::error::Error::FlowServer { - addr, - code, - source: BoxedError::new(err), - location: location!(), - } + Err(BoxedError::new(err)).context(FlowServerSnafu { addr, code }) })? .into_inner(); Ok(response) @@ -88,15 +83,10 @@ impl FlowRequester { let response = client .handle_mirror_request(requests) .await - .map_err(|e| { + .or_else(|e| { let code = e.code(); let err: crate::error::Error = e.into(); - crate::error::Error::FlowServer { - addr, - code, - source: BoxedError::new(err), - location: location!(), - } + Err(BoxedError::new(err)).context(FlowServerSnafu { addr, code }) })? .into_inner(); Ok(response) diff --git a/src/client/src/region.rs b/src/client/src/region.rs index b0c41084a40d..2afbb3dfb065 100644 --- a/src/client/src/region.rs +++ b/src/client/src/region.rs @@ -38,8 +38,8 @@ use substrait::{DFLogicalSubstraitConvertor, SubstraitPlan}; use tokio_stream::StreamExt; use crate::error::{ - self, ConvertFlightDataSnafu, IllegalDatabaseResponseSnafu, IllegalFlightMessagesSnafu, - MissingFieldSnafu, Result, ServerSnafu, + self, ConvertFlightDataSnafu, FlightGetSnafu, IllegalDatabaseResponseSnafu, + IllegalFlightMessagesSnafu, MissingFieldSnafu, Result, ServerSnafu, }; use crate::{metrics, Client, Error}; @@ -103,11 +103,14 @@ impl RegionRequester { let e: error::Error = e.into(); let code = e.status_code(); let msg = e.to_string(); - let error = Error::FlightGet { - tonic_code, - addr: flight_client.addr().to_string(), - source: BoxedError::new(ServerSnafu { code, msg }.build()), - }; + let error = ServerSnafu { code, msg } + .fail::<()>() + .map_err(BoxedError::new) + .with_context(|_| FlightGetSnafu { + tonic_code, + addr: flight_client.addr().to_string(), + }) + .unwrap_err(); error!( e; "Failed to do Flight get, addr: {}, code: {}", flight_client.addr(), diff --git a/src/cmd/src/error.rs b/src/cmd/src/error.rs index 0c2a4fbad961..08c81c414c99 100644 --- a/src/cmd/src/error.rs +++ b/src/cmd/src/error.rs @@ -31,13 +31,6 @@ pub enum Error { source: common_meta::error::Error, }, - #[snafu(display("Failed to iter stream"))] - IterStream { - #[snafu(implicit)] - location: Location, - source: common_meta::error::Error, - }, - #[snafu(display("Failed to init DDL manager"))] InitDdlManager { #[snafu(implicit)] @@ -237,13 +230,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to start catalog manager"))] - StartCatalogManager { - #[snafu(implicit)] - location: Location, - source: catalog::error::Error, - }, - #[snafu(display("Failed to connect to Etcd at {etcd_addr}"))] ConnectEtcd { etcd_addr: String, @@ -253,14 +239,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to connect server at {addr}"))] - ConnectServer { - addr: String, - source: client::error::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to serde json"))] SerdeJson { #[snafu(source)] @@ -278,12 +256,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Expect data from output, but got another thing"))] - NotDataFromOutput { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Empty result from output"))] EmptyResult { #[snafu(implicit)] @@ -346,15 +318,6 @@ pub enum Error { source: meta_client::error::Error, }, - #[snafu(display("Tonic transport error: {error:?} with msg: {msg:?}"))] - TonicTransport { - #[snafu(implicit)] - location: Location, - #[snafu(source)] - error: tonic::transport::Error, - msg: Option, - }, - #[snafu(display("Cannot find schema {schema} in catalog {catalog}"))] SchemaNotFound { catalog: String, @@ -378,18 +341,16 @@ impl ErrorExt for Error { Error::BuildMetaServer { source, .. } => source.status_code(), Error::UnsupportedSelectorType { source, .. } => source.status_code(), - Error::IterStream { source, .. } - | Error::InitMetadata { source, .. } - | Error::InitDdlManager { source, .. } => source.status_code(), + Error::InitMetadata { source, .. } | Error::InitDdlManager { source, .. } => { + source.status_code() + } - Error::ConnectServer { source, .. } => source.status_code(), Error::MissingConfig { .. } | Error::LoadLayeredConfig { .. } | Error::IllegalConfig { .. } | Error::InvalidReplCommand { .. } | Error::InitTimezone { .. } | Error::ConnectEtcd { .. } - | Error::NotDataFromOutput { .. } | Error::CreateDir { .. } | Error::EmptyResult { .. } => StatusCode::InvalidArguments, @@ -407,7 +368,6 @@ impl ErrorExt for Error { source.status_code() } Error::SubstraitEncodeLogicalPlan { source, .. } => source.status_code(), - Error::StartCatalogManager { source, .. } => source.status_code(), Error::SerdeJson { .. } | Error::FileIo { .. } | Error::SpawnThread { .. } => { StatusCode::Unexpected @@ -422,7 +382,6 @@ impl ErrorExt for Error { source.status_code() } Error::MetaClientInit { source, .. } => source.status_code(), - Error::TonicTransport { .. } => StatusCode::Internal, Error::SchemaNotFound { .. } => StatusCode::DatabaseNotFound, } } diff --git a/src/common/catalog/src/error.rs b/src/common/catalog/src/error.rs deleted file mode 100644 index df6e4a4078f5..000000000000 --- a/src/common/catalog/src/error.rs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2023 Greptime Team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::any::Any; - -use common_error::ext::ErrorExt; -use common_error::status_code::StatusCode; -use common_macro::stack_trace_debug; -use snafu::{Location, Snafu}; - -#[derive(Snafu)] -#[snafu(visibility(pub))] -#[stack_trace_debug] -pub enum Error { - #[snafu(display("Invalid full table name: {}", table_name))] - InvalidFullTableName { - table_name: String, - #[snafu(implicit)] - location: Location, - }, -} - -impl ErrorExt for Error { - fn status_code(&self) -> StatusCode { - match self { - Error::InvalidFullTableName { .. } => StatusCode::Unexpected, - } - } - - fn as_any(&self) -> &dyn Any { - self - } -} - -pub type Result = std::result::Result; diff --git a/src/common/catalog/src/lib.rs b/src/common/catalog/src/lib.rs index 7eacc9931e53..1e9534532e22 100644 --- a/src/common/catalog/src/lib.rs +++ b/src/common/catalog/src/lib.rs @@ -15,7 +15,6 @@ use consts::DEFAULT_CATALOG_NAME; pub mod consts; -pub mod error; #[inline] pub fn format_schema_name(catalog: &str, schema: &str) -> String { diff --git a/src/common/grpc-expr/src/error.rs b/src/common/grpc-expr/src/error.rs index 2f27c08bbe41..f025c4d5a5b7 100644 --- a/src/common/grpc-expr/src/error.rs +++ b/src/common/grpc-expr/src/error.rs @@ -64,12 +64,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Invalid column proto: {}", err_msg))] - InvalidColumnProto { - err_msg: String, - #[snafu(implicit)] - location: Location, - }, #[snafu(display("Failed to create vector"))] CreateVector { #[snafu(implicit)] @@ -137,7 +131,6 @@ impl ErrorExt for Error { Error::DuplicatedTimestampColumn { .. } | Error::DuplicatedColumnName { .. } | Error::MissingTimestampColumn { .. } => StatusCode::InvalidArguments, - Error::InvalidColumnProto { .. } => StatusCode::InvalidArguments, Error::CreateVector { .. } => StatusCode::InvalidArguments, Error::MissingField { .. } => StatusCode::InvalidArguments, Error::InvalidColumnDef { source, .. } => source.status_code(), diff --git a/src/common/meta/src/ddl/utils.rs b/src/common/meta/src/ddl/utils.rs index 1b74d3384a7d..fd1737a3e6b7 100644 --- a/src/common/meta/src/ddl/utils.rs +++ b/src/common/meta/src/ddl/utils.rs @@ -15,12 +15,12 @@ use common_catalog::consts::METRIC_ENGINE; use common_error::ext::BoxedError; use common_procedure::error::Error as ProcedureError; -use snafu::{ensure, location, OptionExt}; +use snafu::{ensure, OptionExt, ResultExt}; use store_api::metric_engine_consts::LOGICAL_TABLE_METADATA_KEY; use table::metadata::TableId; use crate::ddl::DetectingRegion; -use crate::error::{Error, Result, TableNotFoundSnafu, UnsupportedSnafu}; +use crate::error::{Error, OperateDatanodeSnafu, Result, TableNotFoundSnafu, UnsupportedSnafu}; use crate::key::table_name::TableNameKey; use crate::key::TableMetadataManagerRef; use crate::peer::Peer; @@ -32,11 +32,9 @@ use crate::ClusterId; pub fn add_peer_context_if_needed(datanode: Peer) -> impl FnOnce(Error) -> Error { move |err| { if !err.is_retry_later() { - return Error::OperateDatanode { - location: location!(), - peer: datanode, - source: BoxedError::new(err), - }; + return Err::<(), BoxedError>(BoxedError::new(err)) + .context(OperateDatanodeSnafu { peer: datanode }) + .unwrap_err(); } err } diff --git a/src/common/meta/src/error.rs b/src/common/meta/src/error.rs index 6de3af36dee3..b244b1e310cc 100644 --- a/src/common/meta/src/error.rs +++ b/src/common/meta/src/error.rs @@ -21,7 +21,7 @@ use common_macro::stack_trace_debug; use common_wal::options::WalOptions; use serde_json::error::Error as JsonError; use snafu::{Location, Snafu}; -use store_api::storage::{RegionId, RegionNumber}; +use store_api::storage::RegionId; use table::metadata::TableId; use crate::peer::Peer; @@ -49,20 +49,6 @@ pub enum Error { region_id: RegionId, }, - #[snafu(display("Invalid result with a txn response: {}", err_msg))] - InvalidTxnResult { - err_msg: String, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Invalid engine type: {}", engine_type))] - InvalidEngineType { - engine_type: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to connect to Etcd"))] ConnectEtcd { #[snafu(source)] @@ -95,15 +81,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Sequence out of range: {}, start={}, step={}", name, start, step))] - SequenceOutOfRange { - name: String, - start: u64, - step: u64, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Unexpected sequence value: {}", err_msg))] UnexpectedSequenceValue { err_msg: String, @@ -327,13 +304,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Catalog already exists, catalog: {}", catalog))] - CatalogAlreadyExists { - catalog: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Schema already exists, catalog:{}, schema: {}", catalog, schema))] SchemaAlreadyExists { catalog: String, @@ -385,13 +355,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to rename table, reason: {}", reason))] - RenameTable { - reason: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid metadata, err: {}", err_msg))] InvalidMetadata { err_msg: String, @@ -423,27 +386,6 @@ pub enum Error { location: Location, }, - #[snafu(display( - "Failed to move region {} in table {}, err: {}", - region, - table_id, - err_msg - ))] - MoveRegion { - table_id: TableId, - region: RegionNumber, - err_msg: String, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Invalid catalog value"))] - InvalidCatalogValue { - source: common_catalog::error::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("External error"))] External { #[snafu(implicit)] @@ -612,13 +554,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Delimiter not found, key: {}", key))] - DelimiterNotFound { - key: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid prefix: {}, key: {}", prefix, key))] MismatchPrefix { prefix: String, @@ -703,14 +638,11 @@ impl ErrorExt for Error { | RouteInfoCorrupted { .. } | InvalidProtoMsg { .. } | InvalidMetadata { .. } - | MoveRegion { .. } | Unexpected { .. } | TableInfoNotFound { .. } | NextSequence { .. } - | SequenceOutOfRange { .. } | UnexpectedSequenceValue { .. } | InvalidHeartbeatResponse { .. } - | InvalidTxnResult { .. } | EncodeJson { .. } | DecodeJson { .. } | PayloadNotExist { .. } @@ -734,22 +666,17 @@ impl ErrorExt for Error { | MetadataCorruption { .. } | StrFromUtf8 { .. } => StatusCode::Unexpected, - SendMessage { .. } | GetKvCache { .. } | CacheNotGet { .. } | RenameTable { .. } => { - StatusCode::Internal - } + SendMessage { .. } | GetKvCache { .. } | CacheNotGet { .. } => StatusCode::Internal, SchemaAlreadyExists { .. } => StatusCode::DatabaseAlreadyExists, ProcedureNotFound { .. } | InvalidViewInfo { .. } | PrimaryKeyNotFound { .. } - | CatalogAlreadyExists { .. } | EmptyKey { .. } - | InvalidEngineType { .. } | AlterLogicalTablesInvalidArguments { .. } | CreateLogicalTablesInvalidArguments { .. } | MismatchPrefix { .. } - | DelimiterNotFound { .. } | TlsConfig { .. } => StatusCode::InvalidArguments, FlowNotFound { .. } => StatusCode::FlowNotFound, @@ -767,7 +694,6 @@ impl ErrorExt for Error { OperateDatanode { source, .. } => source.status_code(), Table { source, .. } => source.status_code(), RetryLater { source, .. } => source.status_code(), - InvalidCatalogValue { source, .. } => source.status_code(), ConvertAlterTableRequest { source, .. } => source.status_code(), ParseProcedureId { .. } diff --git a/src/common/procedure/src/error.rs b/src/common/procedure/src/error.rs index fbad7f3ef2b5..44b827b81c20 100644 --- a/src/common/procedure/src/error.rs +++ b/src/common/procedure/src/error.rs @@ -13,7 +13,6 @@ // limitations under the License. use std::any::Any; -use std::string::FromUtf8Error; use std::sync::Arc; use common_error::ext::{BoxedError, ErrorExt}; @@ -141,12 +140,6 @@ pub enum Error { procedure_id: ProcedureId, }, - #[snafu(display("Corrupted data, error: "))] - CorruptedData { - #[snafu(source)] - error: FromUtf8Error, - }, - #[snafu(display("Failed to start the remove_outdated_meta method, error"))] StartRemoveOutdatedMetaTask { source: common_runtime::error::Error, @@ -161,14 +154,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Subprocedure {} failed", subprocedure_id))] - SubprocedureFailed { - subprocedure_id: ProcedureId, - source: Arc, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to parse segment key: {key}"))] ParseSegmentKey { #[snafu(implicit)] @@ -218,14 +203,11 @@ impl ErrorExt for Error { StatusCode::InvalidArguments } Error::ProcedurePanic { .. } - | Error::CorruptedData { .. } | Error::ParseSegmentKey { .. } | Error::Unexpected { .. } => StatusCode::Unexpected, Error::ProcedureExec { source, .. } => source.status_code(), Error::StartRemoveOutdatedMetaTask { source, .. } | Error::StopRemoveOutdatedMetaTask { source, .. } => source.status_code(), - - Error::SubprocedureFailed { source, .. } => source.status_code(), } } diff --git a/src/common/procedure/src/local/runner.rs b/src/common/procedure/src/local/runner.rs index 345bcde8122d..2f38ae135d23 100644 --- a/src/common/procedure/src/local/runner.rs +++ b/src/common/procedure/src/local/runner.rs @@ -19,10 +19,11 @@ use std::time::Duration; use backon::{BackoffBuilder, ExponentialBuilder}; use common_telemetry::{debug, error, info}; use rand::Rng; +use snafu::ResultExt; use tokio::time; use super::rwlock::OwnedKeyRwLockGuard; -use crate::error::{self, ProcedurePanicSnafu, Result}; +use crate::error::{self, ProcedurePanicSnafu, Result, RollbackTimesExceededSnafu}; use crate::local::{ManagerContext, ProcedureMeta, ProcedureMetaRef}; use crate::procedure::{Output, StringKey}; use crate::store::{ProcedureMessage, ProcedureStore}; @@ -222,12 +223,12 @@ impl Runner { if let Some(d) = rollback.next() { self.wait_on_err(d, rollback_times).await; } else { - self.meta.set_state(ProcedureState::failed(Arc::new( - Error::RollbackTimesExceeded { - source: error.clone(), + let err = Err::<(), Arc>(error) + .context(RollbackTimesExceededSnafu { procedure_id: self.meta.id, - }, - ))); + }) + .unwrap_err(); + self.meta.set_state(ProcedureState::failed(Arc::new(err))); return; } } diff --git a/src/common/query/src/error.rs b/src/common/query/src/error.rs index a41ab6df1127..a7a8de07054e 100644 --- a/src/common/query/src/error.rs +++ b/src/common/query/src/error.rs @@ -127,12 +127,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Not expected to run ExecutionPlan more than once"))] - ExecuteRepeatedly { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("General DataFusion error"))] GeneralDataFusion { #[snafu(source)] @@ -193,12 +187,6 @@ pub enum Error { source: BoxedError, }, - #[snafu(display("Failed to join thread"))] - ThreadJoin { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to decode logical plan: {source}"))] DecodePlan { #[snafu(implicit)] @@ -289,9 +277,7 @@ impl ErrorExt for Error { Error::MissingTableMutationHandler { .. } | Error::MissingProcedureServiceHandler { .. } - | Error::MissingFlowServiceHandler { .. } - | Error::ExecuteRepeatedly { .. } - | Error::ThreadJoin { .. } => StatusCode::Unexpected, + | Error::MissingFlowServiceHandler { .. } => StatusCode::Unexpected, Error::UnsupportedInputDataType { .. } | Error::TypeCast { .. } @@ -327,7 +313,6 @@ pub fn datafusion_status_code( match e { DataFusionError::Internal(_) => StatusCode::Internal, DataFusionError::NotImplemented(_) => StatusCode::Unsupported, - DataFusionError::ResourcesExhausted(_) => StatusCode::RuntimeResourcesExhausted, DataFusionError::Plan(_) => StatusCode::PlanQuery, DataFusionError::External(e) => { if let Some(ext) = (*e).downcast_ref::() { diff --git a/src/common/substrait/src/error.rs b/src/common/substrait/src/error.rs index 00552c9ad2a6..fa7947385bf9 100644 --- a/src/common/substrait/src/error.rs +++ b/src/common/substrait/src/error.rs @@ -17,7 +17,6 @@ use std::any::Any; use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; use common_macro::stack_trace_debug; -use datafusion::error::DataFusionError; use prost::{DecodeError, EncodeError}; use snafu::{Location, Snafu}; @@ -41,14 +40,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Internal error from DataFusion"))] - DFInternal { - #[snafu(source)] - error: DataFusionError, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Internal error"))] Internal { #[snafu(implicit)] @@ -56,12 +47,6 @@ pub enum Error { source: BoxedError, }, - #[snafu(display("Cannot convert plan doesn't belong to GreptimeDB"))] - UnknownPlan { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to encode DataFusion plan"))] EncodeDfPlan { #[snafu(source)] @@ -84,10 +69,8 @@ pub type Result = std::result::Result; impl ErrorExt for Error { fn status_code(&self) -> StatusCode { match self { - Error::UnknownPlan { .. } | Error::EncodeRel { .. } | Error::DecodeRel { .. } => { - StatusCode::InvalidArguments - } - Error::DFInternal { .. } | Error::Internal { .. } => StatusCode::Internal, + Error::EncodeRel { .. } | Error::DecodeRel { .. } => StatusCode::InvalidArguments, + Error::Internal { .. } => StatusCode::Internal, Error::EncodeDfPlan { .. } | Error::DecodeDfPlan { .. } => StatusCode::Unexpected, } } diff --git a/src/common/time/src/error.rs b/src/common/time/src/error.rs index bc2d8600e2ef..45d94a782885 100644 --- a/src/common/time/src/error.rs +++ b/src/common/time/src/error.rs @@ -46,13 +46,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to parse a string into Interval, raw string: {}", raw))] - ParseInterval { - raw: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Current timestamp overflow"))] TimestampOverflow { #[snafu(source)] @@ -115,7 +108,6 @@ impl ErrorExt for Error { Error::InvalidDateStr { .. } | Error::ArithmeticOverflow { .. } => { StatusCode::InvalidArguments } - Error::ParseInterval { .. } => StatusCode::InvalidArguments, } } diff --git a/src/datanode/src/error.rs b/src/datanode/src/error.rs index d070c82fb175..5717d0a40389 100644 --- a/src/datanode/src/error.rs +++ b/src/datanode/src/error.rs @@ -98,13 +98,6 @@ pub enum Error { location: Location, }, - #[snafu(display( - "Columns and values number mismatch, columns: {}, values: {}", - columns, - values - ))] - ColumnValuesNumberMismatch { columns: usize, values: usize }, - #[snafu(display("Failed to delete value from table: {}", table_name))] Delete { table_name: String, @@ -156,13 +149,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Runtime resource error"))] - RuntimeResource { - #[snafu(implicit)] - location: Location, - source: common_runtime::error::Error, - }, - #[snafu(display("Expect KvBackend but not found"))] MissingKvBackend { #[snafu(implicit)] @@ -172,16 +158,6 @@ pub enum Error { #[snafu(display("Invalid SQL, error: {}", msg))] InvalidSql { msg: String }, - #[snafu(display("Not support SQL, error: {}", msg))] - NotSupportSql { msg: String }, - - #[snafu(display("Specified timestamp key or primary key column not found: {}", name))] - KeyColumnNotFound { - name: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Illegal primary keys definition: {}", msg))] IllegalPrimaryKeysDef { msg: String, @@ -210,14 +186,6 @@ pub enum Error { source: meta_client::error::Error, }, - #[snafu(display( - "Table id provider not found, cannot execute SQL directly on datanode in distributed mode" - ))] - TableIdProviderNotFound { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Missing node id in Datanode config"))] MissingNodeId { #[snafu(implicit)] @@ -231,9 +199,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Cannot find requested database: {}-{}", catalog, schema))] - DatabaseNotFound { catalog: String, schema: String }, - #[snafu(display( "No valid default value can be built automatically, column: {}", column, @@ -264,12 +229,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Missing WAL dir config"))] - MissingWalDirConfig { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Unexpected, violated: {}", violated))] Unexpected { violated: String, @@ -320,13 +279,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Unsupported gRPC request, kind: {}", kind))] - UnsupportedGrpcRequest { - kind: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Unsupported output type, expected: {}", expected))] UnsupportedOutput { expected: String, @@ -395,20 +347,6 @@ pub enum Error { #[snafu(implicit)] location: Location, }, - - #[snafu(display("Failed to setup plugin"))] - SetupPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, - - #[snafu(display("Failed to start plugin"))] - StartPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, } pub type Result = std::result::Result; @@ -430,19 +368,14 @@ impl ErrorExt for Error { Delete { source, .. } => source.status_code(), - ColumnValuesNumberMismatch { .. } - | InvalidSql { .. } - | NotSupportSql { .. } - | KeyColumnNotFound { .. } + InvalidSql { .. } | IllegalPrimaryKeysDef { .. } | MissingTimestampColumn { .. } | CatalogNotFound { .. } | SchemaNotFound { .. } | SchemaExists { .. } - | DatabaseNotFound { .. } | MissingNodeId { .. } | ColumnNoneDefaultValue { .. } - | MissingWalDirConfig { .. } | Catalog { .. } | MissingRequiredField { .. } | RegionEngineNotFound { .. } @@ -456,12 +389,9 @@ impl ErrorExt for Error { AsyncTaskExecute { source, .. } => source.status_code(), - CreateDir { .. } - | RemoveDir { .. } - | ShutdownInstance { .. } - | DataFusion { .. } - | SetupPlugin { .. } - | StartPlugin { .. } => StatusCode::Internal, + CreateDir { .. } | RemoveDir { .. } | ShutdownInstance { .. } | DataFusion { .. } => { + StatusCode::Internal + } RegionNotFound { .. } => StatusCode::RegionNotFound, RegionNotReady { .. } => StatusCode::RegionNotReady, @@ -472,11 +402,8 @@ impl ErrorExt for Error { InitBackend { .. } => StatusCode::StorageUnavailable, OpenLogStore { source, .. } => source.status_code(), - RuntimeResource { .. } => StatusCode::RuntimeResourcesExhausted, MetaClientInit { source, .. } => source.status_code(), - UnsupportedOutput { .. } - | TableIdProviderNotFound { .. } - | UnsupportedGrpcRequest { .. } => StatusCode::Unsupported, + UnsupportedOutput { .. } => StatusCode::Unsupported, HandleRegionRequest { source, .. } | GetRegionMetadata { source, .. } | HandleBatchOpenRequest { source, .. } => source.status_code(), diff --git a/src/flow/src/error.rs b/src/flow/src/error.rs index 8b4f3adc65d2..a94de4b6ed7b 100644 --- a/src/flow/src/error.rs +++ b/src/flow/src/error.rs @@ -21,7 +21,6 @@ use common_error::ext::BoxedError; use common_macro::stack_trace_debug; use common_telemetry::common_error::ext::ErrorExt; use common_telemetry::common_error::status_code::StatusCode; -use datatypes::value::Value; use snafu::{Location, Snafu}; use crate::adapter::FlowId; @@ -69,13 +68,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Table already exist: {name}"))] - TableAlreadyExist { - name: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Flow not found, id={id}"))] FlowNotFound { id: FlowId, @@ -106,13 +98,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Invalid query: prost can't decode substrait plan: {inner}"))] - InvalidQueryProst { - inner: api::DecodeError, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid query: {reason}"))] InvalidQuery { reason: String, @@ -120,13 +105,6 @@ pub enum Error { location: Location, }, - #[snafu(display("No protobuf type for value: {value}"))] - NoProtoType { - value: Value, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Not implement in flow: {reason}"))] NotImplemented { reason: String, @@ -214,21 +192,18 @@ pub type Result = std::result::Result; impl ErrorExt for Error { fn status_code(&self) -> StatusCode { match self { - Self::Eval { .. } | &Self::JoinTask { .. } | &Self::Datafusion { .. } => { + Self::Eval { .. } | Self::JoinTask { .. } | Self::Datafusion { .. } => { StatusCode::Internal } - &Self::TableAlreadyExist { .. } | Self::FlowAlreadyExist { .. } => { - StatusCode::TableAlreadyExists - } + Self::FlowAlreadyExist { .. } => StatusCode::TableAlreadyExists, Self::TableNotFound { .. } | Self::TableNotFoundMeta { .. } | Self::FlowNotFound { .. } | Self::ListFlows { .. } => StatusCode::TableNotFound, - Self::InvalidQueryProst { .. } - | &Self::InvalidQuery { .. } - | &Self::Plan { .. } - | &Self::Datatypes { .. } => StatusCode::PlanQuery, - Self::NoProtoType { .. } | Self::Unexpected { .. } => StatusCode::Unexpected, + Self::InvalidQuery { .. } | Self::Plan { .. } | Self::Datatypes { .. } => { + StatusCode::PlanQuery + } + Self::Unexpected { .. } => StatusCode::Unexpected, Self::NotImplemented { .. } | Self::UnsupportedTemporalFilter { .. } => { StatusCode::Unsupported } diff --git a/src/frontend/src/error.rs b/src/frontend/src/error.rs index cb0df405c597..742deaf8081b 100644 --- a/src/frontend/src/error.rs +++ b/src/frontend/src/error.rs @@ -20,7 +20,6 @@ use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; use common_macro::stack_trace_debug; use snafu::{Location, Snafu}; -use store_api::storage::RegionNumber; #[derive(Snafu)] #[snafu(visibility(pub))] @@ -61,13 +60,6 @@ pub enum Error { source: common_meta::error::Error, }, - #[snafu(display("Runtime resource error"))] - RuntimeResource { - #[snafu(implicit)] - location: Location, - source: common_runtime::error::Error, - }, - #[snafu(display("Failed to start server"))] StartServer { #[snafu(implicit)] @@ -96,13 +88,6 @@ pub enum Error { source: sql::error::Error, }, - #[snafu(display("Failed to convert vector to GRPC column, reason: {}", reason))] - VectorToGrpcColumn { - reason: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid SQL, error: {}", err_msg))] InvalidSql { err_msg: String, @@ -117,13 +102,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to find Datanode by region: {:?}", region))] - FindDatanode { - region: RegionNumber, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid InsertRequest, reason: {}", reason))] InvalidInsertRequest { reason: String, @@ -220,20 +198,6 @@ pub enum Error { source: servers::error::Error, }, - #[snafu(display("Failed to find leaders when altering table, table: {}", table))] - LeaderNotFound { - table: String, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Failed to found context value: {}", key))] - ContextValueNotFound { - key: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Not supported: {}", feat))] NotSupported { feat: String }, @@ -282,14 +246,6 @@ pub enum Error { source: script::error::Error, }, - #[snafu(display("Failed to copy table: {}", table_name))] - CopyTable { - table_name: String, - #[snafu(implicit)] - location: Location, - source: table::error::Error, - }, - #[snafu(display("Failed to insert value into table: {}", table_name))] Insert { table_name: String, @@ -312,13 +268,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Empty data: {}", msg))] - EmptyData { - msg: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display( "No valid default value can be built automatically, column: {}", column, @@ -364,20 +313,6 @@ pub enum Error { #[snafu(implicit)] location: Location, }, - - #[snafu(display("Failed to setup plugin"))] - SetupPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, - - #[snafu(display("Failed to start plugin"))] - StartPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, } pub type Result = std::result::Result; @@ -395,7 +330,6 @@ impl ErrorExt for Error { | Error::ColumnNotFound { .. } | Error::UnsupportedFormat { .. } | Error::IllegalAuthConfig { .. } - | Error::EmptyData { .. } | Error::ColumnNoneDefaultValue { .. } | Error::IncompleteGrpcRequest { .. } | Error::InvalidTlsConfig { .. } => StatusCode::InvalidArguments, @@ -408,7 +342,6 @@ impl ErrorExt for Error { Error::HandleHeartbeatResponse { source, .. } => source.status_code(), - Error::RuntimeResource { source, .. } => source.status_code(), Error::PromStoreRemoteQueryPlan { source, .. } | Error::ExecutePromql { source, .. } => source.status_code(), @@ -420,25 +353,16 @@ impl ErrorExt for Error { Error::InvalidateTableCache { source, .. } => source.status_code(), - Error::Table { source, .. } - | Error::CopyTable { source, .. } - | Error::Insert { source, .. } => source.status_code(), + Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(), Error::OpenRaftEngineBackend { .. } => StatusCode::StorageUnavailable, Error::RequestQuery { source, .. } => source.status_code(), - Error::FindDatanode { .. } => StatusCode::RegionNotReady, - - Error::VectorToGrpcColumn { .. } - | Error::CacheRequired { .. } - | Error::SetupPlugin { .. } - | Error::StartPlugin { .. } => StatusCode::Internal, + Error::CacheRequired { .. } => StatusCode::Internal, Error::InvalidRegionRequest { .. } => StatusCode::IllegalState, - Error::ContextValueNotFound { .. } => StatusCode::Unexpected, - Error::TableNotFound { .. } => StatusCode::TableNotFound, Error::Catalog { source, .. } => source.status_code(), @@ -450,7 +374,6 @@ impl ErrorExt for Error { | Error::ReadTable { source, .. } | Error::ExecLogicalPlan { source, .. } => source.status_code(), - Error::LeaderNotFound { .. } => StatusCode::StorageUnavailable, Error::InvokeRegionServer { source, .. } => source.status_code(), Error::External { source, .. } => source.status_code(), diff --git a/src/index/src/inverted_index/create/sort/intermediate_rw/codec_v1.rs b/src/index/src/inverted_index/create/sort/intermediate_rw/codec_v1.rs index 9cf6b14e0d65..8e4feb9902fa 100644 --- a/src/index/src/inverted_index/create/sort/intermediate_rw/codec_v1.rs +++ b/src/index/src/inverted_index/create/sort/intermediate_rw/codec_v1.rs @@ -17,9 +17,9 @@ use std::io; use asynchronous_codec::{BytesMut, Decoder, Encoder}; use bytes::{Buf, BufMut}; use common_base::BitVec; -use snafu::location; +use snafu::ResultExt; -use crate::inverted_index::error::{Error, Result}; +use crate::inverted_index::error::{CommonIoSnafu, Error, Result}; use crate::inverted_index::Bytes; const U64_LENGTH: usize = std::mem::size_of::(); @@ -105,10 +105,9 @@ impl Decoder for IntermediateItemDecoderV1 { /// Required for [`Encoder`] and [`Decoder`] implementations. impl From for Error { fn from(error: io::Error) -> Self { - Error::CommonIoError { - error, - location: location!(), - } + Err::<(), io::Error>(error) + .context(CommonIoSnafu) + .unwrap_err() } } diff --git a/src/index/src/inverted_index/error.rs b/src/index/src/inverted_index/error.rs index 0e151db71893..07a42b8b8767 100644 --- a/src/index/src/inverted_index/error.rs +++ b/src/index/src/inverted_index/error.rs @@ -182,7 +182,7 @@ pub enum Error { }, #[snafu(display("Failed to perform IO operation"))] - CommonIoError { + CommonIo { #[snafu(source)] error: IoError, #[snafu(implicit)] @@ -227,7 +227,7 @@ impl ErrorExt for Error { | DecodeProto { .. } | DecodeFst { .. } | KeysApplierUnexpectedPredicates { .. } - | CommonIoError { .. } + | CommonIo { .. } | UnknownIntermediateCodecMagic { .. } | FstCompile { .. } => StatusCode::Unexpected, diff --git a/src/log-store/src/error.rs b/src/log-store/src/error.rs index 26753919b53f..962606666bd7 100644 --- a/src/log-store/src/error.rs +++ b/src/log-store/src/error.rs @@ -136,12 +136,6 @@ pub enum Error { error: rskafka::client::error::Error, }, - #[snafu(display("Failed to found client"))] - ClientNotFount { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to resolve Kafka broker endpoint."))] ResolveKafkaEndpoint { source: common_wal::error::Error }, @@ -159,18 +153,6 @@ pub enum Error { error: rskafka::client::error::Error, }, - #[snafu(display( - "Failed to get a Kafka topic client, topic: {}, source: {}", - topic, - error - ))] - GetClient { - topic: String, - #[snafu(implicit)] - location: Location, - error: String, - }, - #[snafu(display("Missing required key in a record"))] MissingKey { #[snafu(implicit)] @@ -183,12 +165,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Cannot build a record from empty entries"))] - EmptyEntries { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to produce records to Kafka, topic: {}, size: {}", topic, size))] ProduceRecord { topic: String, diff --git a/src/meta-client/src/error.rs b/src/meta-client/src/error.rs index 9116598590dc..33a960d9f22f 100644 --- a/src/meta-client/src/error.rs +++ b/src/meta-client/src/error.rs @@ -33,12 +33,6 @@ pub enum Error { #[snafu(display("{}", msg))] MetaServer { code: StatusCode, msg: String }, - #[snafu(display("Failed to ask leader from all endpoints"))] - AskLeader { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("No leader, should ask leader first"))] NoLeader { #[snafu(implicit)] @@ -116,7 +110,6 @@ impl ErrorExt for Error { fn status_code(&self) -> StatusCode { match self { Error::IllegalGrpcClientState { .. } - | Error::AskLeader { .. } | Error::NoLeader { .. } | Error::AskLeaderTimeout { .. } | Error::NotStarted { .. } diff --git a/src/meta-srv/src/error.rs b/src/meta-srv/src/error.rs index a41dd6387237..a6f3721f3092 100644 --- a/src/meta-srv/src/error.rs +++ b/src/meta-srv/src/error.rs @@ -16,7 +16,6 @@ use common_error::define_into_tonic_status; use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; use common_macro::stack_trace_debug; -use common_meta::peer::Peer; use common_meta::DatanodeId; use common_runtime::JoinError; use rand::distributions::WeightedError; @@ -116,14 +115,6 @@ pub enum Error { source: common_meta::error::Error, }, - #[snafu(display("Failed to operate region on peer:{}", peer))] - OperateRegion { - #[snafu(implicit)] - location: Location, - peer: Peer, - source: BoxedError, - }, - #[snafu(display("Failed to list catalogs"))] ListCatalogs { #[snafu(implicit)] @@ -156,25 +147,6 @@ pub enum Error { error: JoinError, }, - #[snafu(display("Failed to execute transaction: {}", msg))] - Txn { - #[snafu(implicit)] - location: Location, - msg: String, - }, - - #[snafu(display( - "Unexpected table_id changed, expected: {}, found: {}", - expected, - found, - ))] - TableIdChanged { - #[snafu(implicit)] - location: Location, - expected: u64, - found: u64, - }, - #[snafu(display( "Failed to request {}, required: {}, but only {} available", select_target, @@ -189,14 +161,6 @@ pub enum Error { select_target: SelectTarget, }, - #[snafu(display("Failed to request Datanode {}", peer))] - RequestDatanode { - #[snafu(implicit)] - location: Location, - peer: Peer, - source: client::Error, - }, - #[snafu(display("Failed to send shutdown signal"))] SendShutdownSignal { #[snafu(source)] @@ -255,35 +219,27 @@ pub enum Error { #[snafu(implicit)] location: Location, }, + #[snafu(display("Failed to start http server"))] StartHttp { #[snafu(implicit)] location: Location, source: servers::error::Error, }, + #[snafu(display("Failed to init export metrics task"))] InitExportMetricsTask { #[snafu(implicit)] location: Location, source: servers::error::Error, }, - #[snafu(display("Failed to parse duration {}", duration))] - ParseDuration { - duration: String, - #[snafu(source)] - error: humantime::DurationError, - }, + #[snafu(display("Failed to parse address {}", addr))] ParseAddr { addr: String, #[snafu(source)] error: std::net::AddrParseError, }, - #[snafu(display("Empty table name"))] - EmptyTableName { - #[snafu(implicit)] - location: Location, - }, #[snafu(display("Invalid lease key: {}", key))] InvalidLeaseKey { @@ -389,28 +345,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Cannot parse catalog value"))] - InvalidCatalogValue { - #[snafu(implicit)] - location: Location, - source: common_catalog::error::Error, - }, - - #[snafu(display("Cannot parse full table name"))] - InvalidFullTableName { - #[snafu(implicit)] - location: Location, - source: common_catalog::error::Error, - }, - - #[snafu(display("Failed to decode table route"))] - DecodeTableRoute { - #[snafu(source)] - error: prost::DecodeError, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to find table route for {table_id}"))] TableRouteNotFound { table_id: TableId, @@ -440,14 +374,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Table route corrupted, key: {}, reason: {}", key, reason))] - CorruptedTableRoute { - key: String, - reason: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Metasrv has no leader at this moment"))] NoLeader { #[snafu(implicit)] @@ -461,16 +387,6 @@ pub enum Error { location: Location, }, - #[snafu(display( - "Failed to move the value of {} because other clients caused a race condition", - key - ))] - MoveValue { - key: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Unsupported selector type, {}", selector_type))] UnsupportedSelectorType { selector_type: String, @@ -565,12 +481,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Distributed lock is not configured"))] - LockNotConfig { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid utf-8 value"))] InvalidUtf8Value { #[snafu(source)] @@ -688,13 +598,6 @@ pub enum Error { source: common_procedure::error::Error, }, - #[snafu(display("Failed to find failover candidates for region: {}", failed_region))] - RegionFailoverCandidatesNotFound { - failed_region: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display( "Received unexpected instruction reply, mailbox message: {}, reason: {}", mailbox_message, @@ -722,20 +625,6 @@ pub enum Error { source: BoxedError, }, - #[snafu(display("Failed to update table metadata, err_msg: {}", err_msg))] - UpdateTableMetadata { - err_msg: String, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Failed to convert table route"))] - TableRouteConversion { - #[snafu(implicit)] - location: Location, - source: common_meta::error::Error, - }, - #[snafu(display("Failed to convert proto data"))] ConvertProtoData { #[snafu(implicit)] @@ -766,20 +655,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to update table route"))] - UpdateTableRoute { - source: common_meta::error::Error, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Failed to get table info error"))] - GetFullTableInfo { - source: common_meta::error::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid heartbeat request: {}", err_msg))] InvalidHeartbeatRequest { err_msg: String, @@ -852,20 +727,6 @@ pub enum Error { source: Box, }, - #[snafu(display("Failed to setup plugin"))] - SetupPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, - - #[snafu(display("Failed to start plugin"))] - StartPlugin { - #[snafu(implicit)] - location: Location, - source: BoxedError, - }, - #[cfg(feature = "pg_kvbackend")] #[snafu(display("Failed to execute via postgres"))] PostgresExecution { @@ -904,7 +765,6 @@ impl ErrorExt for Error { | Error::TcpIncoming { .. } | Error::SerializeToJson { .. } | Error::DeserializeFromJson { .. } - | Error::DecodeTableRoute { .. } | Error::NoLeader { .. } | Error::CreateChannel { .. } | Error::BatchGet { .. } @@ -915,7 +775,6 @@ impl ErrorExt for Error { | Error::Lock { .. } | Error::Unlock { .. } | Error::LeaseGrant { .. } - | Error::LockNotConfig { .. } | Error::ExceededRetryLimit { .. } | Error::SendShutdownSignal { .. } | Error::PusherNotFound { .. } @@ -926,15 +785,12 @@ impl ErrorExt for Error { | Error::RetryLater { .. } | Error::RetryLaterWithSource { .. } | Error::StartGrpc { .. } - | Error::UpdateTableMetadata { .. } | Error::NoEnoughAvailableNode { .. } | Error::PublishMessage { .. } | Error::Join { .. } | Error::WeightArray { .. } | Error::NotSetWeightArray { .. } - | Error::PeerUnavailable { .. } - | Error::SetupPlugin { .. } - | Error::StartPlugin { .. } => StatusCode::Internal, + | Error::PeerUnavailable { .. } => StatusCode::Internal, Error::Unsupported { .. } => StatusCode::Unsupported, @@ -944,14 +800,12 @@ impl ErrorExt for Error { Error::EmptyKey { .. } | Error::MissingRequiredParameter { .. } | Error::MissingRequestHeader { .. } - | Error::EmptyTableName { .. } | Error::InvalidLeaseKey { .. } | Error::InvalidStatKey { .. } | Error::InvalidInactiveRegionKey { .. } | Error::ParseNum { .. } | Error::ParseBool { .. } | Error::ParseAddr { .. } - | Error::ParseDuration { .. } | Error::UnsupportedSelectorType { .. } | Error::InvalidArguments { .. } | Error::InitExportMetricsTask { .. } @@ -967,13 +821,9 @@ impl ErrorExt for Error { | Error::TableRouteNotFound { .. } | Error::TableInfoNotFound { .. } | Error::DatanodeTableNotFound { .. } - | Error::CorruptedTableRoute { .. } - | Error::MoveValue { .. } | Error::InvalidUtf8Value { .. } | Error::UnexpectedInstructionReply { .. } | Error::Unexpected { .. } - | Error::Txn { .. } - | Error::TableIdChanged { .. } | Error::RegionOpeningRace { .. } | Error::RegionRouteNotFound { .. } | Error::MigrationAbort { .. } @@ -982,9 +832,6 @@ impl ErrorExt for Error { Error::SaveClusterInfo { source, .. } | Error::InvalidClusterInfoFormat { source, .. } => source.status_code(), Error::InvalidateTableCache { source, .. } => source.status_code(), - Error::RequestDatanode { source, .. } => source.status_code(), - Error::InvalidCatalogValue { source, .. } - | Error::InvalidFullTableName { source, .. } => source.status_code(), Error::SubmitProcedure { source, .. } | Error::WaitProcedure { source, .. } | Error::QueryProcedure { source, .. } => source.status_code(), @@ -999,18 +846,13 @@ impl ErrorExt for Error { | Error::ListTables { source, .. } => source.status_code(), Error::StartTelemetryTask { source, .. } => source.status_code(), - Error::RegionFailoverCandidatesNotFound { .. } => StatusCode::RuntimeResourcesExhausted, Error::NextSequence { source, .. } => source.status_code(), Error::RegisterProcedureLoader { source, .. } => source.status_code(), - Error::OperateRegion { source, .. } => source.status_code(), Error::SubmitDdlTask { source, .. } => source.status_code(), - Error::TableRouteConversion { source, .. } - | Error::ConvertProtoData { source, .. } + Error::ConvertProtoData { source, .. } | Error::TableMetadataManager { source, .. } | Error::KvBackend { source, .. } - | Error::UpdateTableRoute { source, .. } - | Error::GetFullTableInfo { source, .. } | Error::UnexpectedLogicalRouteTable { source, .. } => source.status_code(), Error::InitMetadata { source, .. } | Error::InitDdlManager { source, .. } => { diff --git a/src/metric-engine/src/error.rs b/src/metric-engine/src/error.rs index b16cd9222d47..7827a07fd205 100644 --- a/src/metric-engine/src/error.rs +++ b/src/metric-engine/src/error.rs @@ -26,13 +26,6 @@ use store_api::storage::RegionId; #[snafu(visibility(pub))] #[stack_trace_debug] pub enum Error { - #[snafu(display("Missing internal column {} in physical metric table", column))] - MissingInternalColumn { - column: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to create mito region, region type: {}", region_type))] CreateMitoRegion { region_type: String, @@ -64,15 +57,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to deserialize semantic type from {}", raw))] - DeserializeSemanticType { - raw: String, - #[snafu(source)] - error: serde_json::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to deserialize column metadata from {}", raw))] DeserializeColumnMetadata { raw: String, @@ -135,13 +119,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Mito compact operation fails"))] - MitoCompactOperation { - source: BoxedError, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to collect record batch stream"))] CollectRecordBatchStream { source: common_recordbatch::error::Error, @@ -270,9 +247,7 @@ impl ErrorExt for Error { StatusCode::Unsupported } - MissingInternalColumn { .. } - | DeserializeSemanticType { .. } - | DeserializeColumnMetadata { .. } + DeserializeColumnMetadata { .. } | SerializeColumnMetadata { .. } | DecodeColumnValue { .. } | ParseRegionId { .. } @@ -290,8 +265,7 @@ impl ErrorExt for Error { | MitoReadOperation { source, .. } | MitoWriteOperation { source, .. } | MitoCatchupOperation { source, .. } - | MitoFlushOperation { source, .. } - | MitoCompactOperation { source, .. } => source.status_code(), + | MitoFlushOperation { source, .. } => source.status_code(), CollectRecordBatchStream { source, .. } => source.status_code(), diff --git a/src/mito2/src/error.rs b/src/mito2/src/error.rs index 2038656a2333..2d045e8c579a 100644 --- a/src/mito2/src/error.rs +++ b/src/mito2/src/error.rs @@ -583,13 +583,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to read puffin metadata"))] - PuffinReadMetadata { - source: puffin::error::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to read puffin blob"))] PuffinReadBlob { source: puffin::error::Error, @@ -678,8 +671,8 @@ pub enum Error { location: Location, }, - #[snafu(display("BiError, first: {first}, second: {second}"))] - BiError { + #[snafu(display("BiErrors, first: {first}, second: {second}"))] + BiErrors { first: Box, second: Box, #[snafu(implicit)] @@ -929,7 +922,7 @@ impl ErrorExt for Error { | ConvertMetaData { .. } | DecodeWal { .. } | ComputeArrow { .. } - | BiError { .. } + | BiErrors { .. } | StopScheduler { .. } | ComputeVector { .. } | SerializeField { .. } @@ -970,8 +963,7 @@ impl ErrorExt for Error { | PushIndexValue { source, .. } | ApplyInvertedIndex { source, .. } | IndexFinish { source, .. } => source.status_code(), - PuffinReadMetadata { source, .. } - | PuffinReadBlob { source, .. } + PuffinReadBlob { source, .. } | PuffinAddBlob { source, .. } | PuffinInitStager { source, .. } | PuffinBuildReader { source, .. } => source.status_code(), diff --git a/src/mito2/src/sst/index/inverted_index/creator.rs b/src/mito2/src/sst/index/inverted_index/creator.rs index 4cf20b94769a..b2b11048193f 100644 --- a/src/mito2/src/sst/index/inverted_index/creator.rs +++ b/src/mito2/src/sst/index/inverted_index/creator.rs @@ -32,8 +32,8 @@ use tokio::io::duplex; use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; use crate::error::{ - BiSnafu, IndexFinishSnafu, OperateAbortedIndexSnafu, PuffinAddBlobSnafu, PushIndexValueSnafu, - Result, + BiErrorsSnafu, IndexFinishSnafu, OperateAbortedIndexSnafu, PuffinAddBlobSnafu, + PushIndexValueSnafu, Result, }; use crate::read::Batch; use crate::sst::file::FileId; @@ -246,7 +246,7 @@ impl InvertedIndexer { puffin_add_blob.context(PuffinAddBlobSnafu), index_finish.context(IndexFinishSnafu), ) { - (Err(e1), Err(e2)) => BiSnafu { + (Err(e1), Err(e2)) => BiErrorsSnafu { first: Box::new(e1), second: Box::new(e2), } diff --git a/src/operator/src/error.rs b/src/operator/src/error.rs index 2473128137df..02a880a90342 100644 --- a/src/operator/src/error.rs +++ b/src/operator/src/error.rs @@ -462,14 +462,6 @@ pub enum Error { error: regex::Error, }, - #[snafu(display("Failed to copy table: {}", table_name))] - CopyTable { - table_name: String, - #[snafu(implicit)] - location: Location, - source: table::error::Error, - }, - #[snafu(display("Failed to insert value into table: {}", table_name))] Insert { table_name: String, @@ -835,9 +827,7 @@ impl ErrorExt for Error { source.status_code() } - Error::Table { source, .. } - | Error::CopyTable { source, .. } - | Error::Insert { source, .. } => source.status_code(), + Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(), Error::ConvertColumnDefaultConstraint { source, .. } | Error::CreateTableInfo { source, .. } diff --git a/src/partition/src/error.rs b/src/partition/src/error.rs index b7ece9e7f961..92d2f560d4ff 100644 --- a/src/partition/src/error.rs +++ b/src/partition/src/error.rs @@ -20,7 +20,7 @@ use common_macro::stack_trace_debug; use datafusion_common::ScalarValue; use datafusion_expr::expr::Expr; use snafu::{Location, Snafu}; -use store_api::storage::{RegionId, RegionNumber}; +use store_api::storage::RegionId; use table::metadata::TableId; use crate::expr::PartitionExpr; @@ -50,14 +50,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to find Datanode, table id: {}, region: {}", table_id, region))] - FindDatanode { - table_id: TableId, - region: RegionNumber, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to find table routes for table id {}", table_id))] FindTableRoutes { table_id: TableId, @@ -93,9 +85,6 @@ pub enum Error { location: Location, }, - #[snafu(display("The column '{}' does not have a default value.", column))] - MissingDefaultValue { column: String }, - #[snafu(display("Expect {} region keys, actual {}", expect, actual))] RegionKeysSize { expect: usize, @@ -224,12 +213,9 @@ impl ErrorExt for Error { Error::Unexpected { .. } => StatusCode::Unexpected, Error::InvalidTableRouteData { .. } => StatusCode::TableUnavailable, - Error::FindTableRoutes { .. } | Error::FindDatanode { .. } => { - StatusCode::TableUnavailable - } + Error::FindTableRoutes { .. } => StatusCode::TableUnavailable, Error::TableRouteNotFound { .. } => StatusCode::TableNotFound, Error::TableRouteManager { source, .. } => source.status_code(), - Error::MissingDefaultValue { .. } => StatusCode::IllegalState, Error::UnexpectedLogicalRouteTable { source, .. } => source.status_code(), } } diff --git a/src/puffin/src/error.rs b/src/puffin/src/error.rs index b30c542f4ea8..57aec44d1fb8 100644 --- a/src/puffin/src/error.rs +++ b/src/puffin/src/error.rs @@ -106,7 +106,7 @@ pub enum Error { }, #[snafu(display("Error while walking directory"))] - WalkDirError { + WalkDir { #[snafu(source)] error: async_walkdir::Error, #[snafu(implicit)] @@ -286,7 +286,7 @@ impl ErrorExt for Error { | BlobNotFound { .. } | BlobIndexOutOfBound { .. } | FileKeyNotMatch { .. } - | WalkDirError { .. } => StatusCode::Unexpected, + | WalkDir { .. } => StatusCode::Unexpected, UnsupportedCompression { .. } | UnsupportedDecompression { .. } => { StatusCode::Unsupported diff --git a/src/query/src/datafusion/error.rs b/src/query/src/datafusion/error.rs index f287268c01b2..c4f0575f7661 100644 --- a/src/query/src/datafusion/error.rs +++ b/src/query/src/datafusion/error.rs @@ -33,12 +33,6 @@ pub enum InnerError { location: Location, }, - #[snafu(display("PhysicalPlan downcast failed"))] - PhysicalPlanDowncast { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Fail to convert arrow schema"))] ConvertSchema { #[snafu(implicit)] @@ -61,7 +55,7 @@ impl ErrorExt for InnerError { match self { // TODO(yingwen): Further categorize datafusion error. Datafusion { .. } => StatusCode::EngineExecuteQuery, - PhysicalPlanDowncast { .. } | ConvertSchema { .. } => StatusCode::Unexpected, + ConvertSchema { .. } => StatusCode::Unexpected, ConvertDfRecordBatchStream { source, .. } => source.status_code(), } } diff --git a/src/servers/src/error.rs b/src/servers/src/error.rs index a5c03fbf464a..43bb458bd5d2 100644 --- a/src/servers/src/error.rs +++ b/src/servers/src/error.rs @@ -19,7 +19,6 @@ use std::string::FromUtf8Error; use axum::response::{IntoResponse, Response}; use axum::{http, Json}; use base64::DecodeError; -use catalog; use common_error::define_into_tonic_status; use common_error::ext::{BoxedError, ErrorExt}; use common_error::status_code::StatusCode; @@ -197,20 +196,6 @@ pub enum Error { source: common_grpc::error::Error, }, - #[snafu(display("Failed to write prometheus series"))] - PromSeriesWrite { - #[snafu(implicit)] - location: Location, - source: common_grpc::error::Error, - }, - - #[snafu(display("Failed to write OTLP metrics"))] - OtlpMetricsWrite { - #[snafu(implicit)] - location: Location, - source: common_grpc::error::Error, - }, - #[snafu(display("Failed to convert time precision, name: {}", name))] TimePrecision { name: String, @@ -218,12 +203,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Connection reset by peer"))] - ConnResetByPeer { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Hyper error"))] Hyper { #[snafu(source)] @@ -373,20 +352,12 @@ pub enum Error { }, #[snafu(display("Error accessing catalog"))] - CatalogError { + Catalog { source: catalog::error::Error, #[snafu(implicit)] location: Location, }, - #[snafu(display("Cannot find requested database: {}.{}", catalog, schema))] - DatabaseNotFound { - catalog: String, - schema: String, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Cannot find requested table: {}.{}.{}", catalog, schema, table))] TableNotFound { catalog: String, @@ -411,21 +382,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Invalid flush argument: {}", err_msg))] - InvalidFlushArgument { - err_msg: String, - #[snafu(implicit)] - location: Location, - }, - - #[snafu(display("Failed to build gRPC reflection service"))] - GrpcReflectionService { - #[snafu(source)] - error: tonic_reflection::server::Error, - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to build HTTP response"))] BuildHttpResponse { #[snafu(source)] @@ -550,12 +506,6 @@ pub enum Error { location: Location, }, - #[snafu(display("Failed to convert to structured log"))] - ToStructuredLog { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Unsupported content type: {:?}", content_type))] UnsupportedContentType { content_type: ContentType, @@ -584,14 +534,6 @@ pub enum Error { location: Location, }, - #[snafu(display( - "Invalid parameter, physical_table is not expected when metric engine is disabled" - ))] - UnexpectedPhysicalTable { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Failed to initialize a watcher for file {}", path))] FileWatch { path: String, @@ -621,7 +563,6 @@ impl ErrorExt for Error { | TcpBind { .. } | SendPromRemoteRequest { .. } | TcpIncoming { .. } - | GrpcReflectionService { .. } | BuildHttpResponse { .. } | Arrow { .. } | FileWatch { .. } => StatusCode::Internal, @@ -630,8 +571,6 @@ impl ErrorExt for Error { StatusCode::IllegalState } - CatalogError { source, .. } => source.status_code(), - UnsupportedDataType { .. } => StatusCode::Unsupported, #[cfg(not(windows))] @@ -653,7 +592,6 @@ impl ErrorExt for Error { | InvalidParameter { .. } | InvalidQuery { .. } | InfluxdbLineProtocol { .. } - | ConnResetByPeer { .. } | InvalidOpentsdbJsonRequest { .. } | DecodePromRemoteRequest { .. } | DecodeOtlpRequest { .. } @@ -671,15 +609,12 @@ impl ErrorExt for Error { | IncompatibleSchema { .. } | MissingQueryContext { .. } | MysqlValueConversion { .. } - | UnexpectedPhysicalTable { .. } | ParseJson { .. } - | ToStructuredLog { .. } | UnsupportedContentType { .. } | TimestampOverflow { .. } => StatusCode::InvalidArguments, - RowWriter { source, .. } - | PromSeriesWrite { source, .. } - | OtlpMetricsWrite { source, .. } => source.status_code(), + Catalog { source, .. } => source.status_code(), + RowWriter { source, .. } => source.status_code(), Hyper { .. } => StatusCode::Unknown, TlsRequired { .. } => StatusCode::Unknown, @@ -693,14 +628,12 @@ impl ErrorExt for Error { | InvalidBase64Value { .. } | InvalidAuthHeaderInvalidUtf8Value { .. } => StatusCode::InvalidAuthHeader, - DatabaseNotFound { .. } => StatusCode::DatabaseNotFound, - TableNotFound { .. } => StatusCode::TableNotFound, #[cfg(feature = "mem-prof")] DumpProfileData { source, .. } => source.status_code(), - InvalidUtf8Value { .. } | InvalidFlushArgument { .. } => StatusCode::InvalidArguments, + InvalidUtf8Value { .. } => StatusCode::InvalidArguments, ReplacePreparedStmtParams { source, .. } | GetPreparedStmtParams { source, .. } diff --git a/src/servers/src/mysql/server.rs b/src/servers/src/mysql/server.rs index 8dfb6d141544..146295bbaf34 100644 --- a/src/servers/src/mysql/server.rs +++ b/src/servers/src/mysql/server.rs @@ -24,12 +24,13 @@ use futures::StreamExt; use opensrv_mysql::{ plain_run_with_options, secure_run_with_options, AsyncMysqlIntermediary, IntermediaryOptions, }; +use snafu::ensure; use tokio; use tokio::io::BufWriter; use tokio::net::TcpStream; use tokio_rustls::rustls::ServerConfig; -use crate::error::{Error, Result}; +use crate::error::{Error, Result, TlsRequiredSnafu}; use crate::mysql::handler::MysqlInstanceShim; use crate::query_handler::sql::ServerSqlQueryHandlerRef; use crate::server::{AbortableStream, BaseTcpServer, Server}; @@ -191,11 +192,12 @@ impl MysqlServer { AsyncMysqlIntermediary::init_before_ssl(&mut shim, &mut r, &mut w, &spawn_config.tls()) .await?; - if spawn_config.force_tls && !client_tls { - return Err(Error::TlsRequired { - server: "mysql".to_owned(), - }); - } + ensure!( + !spawn_config.force_tls || client_tls, + TlsRequiredSnafu { + server: "mysql".to_owned() + } + ); match spawn_config.tls() { Some(tls_conf) if client_tls => {