Skip to content

Commit

Permalink
refactor: common-exception crate should be independent of `meta-typ…
Browse files Browse the repository at this point in the history
…es` (#14275)

The `databend-common-exception` crate, which is a general-purpose
library, should not have a dependency on the business-specific
`databend-common-meta-types` crate.

With this commit, we've relocated the conversion logic for transforming
`Meta**` errors into `ErrorCode`. These conversions are now handled
within the meta-service related crates: `databend-common-meta-types` and
`databend-common-sto-error`.
  • Loading branch information
drmingdrmer authored Jan 9, 2024
1 parent a053456 commit 75622f3
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ test = false

[dependencies] # In alphabetical order
databend-common-arrow = { path = "../arrow" }
databend-common-meta-stoerr = { path = "../../meta/stoerr" }
databend-common-meta-types = { path = "../../meta/types" }

# GitHub dependencies
# TODO: Use the version from crates.io once
Expand Down
22 changes: 0 additions & 22 deletions src/common/exception/src/exception_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ use std::fmt::Display;
use std::fmt::Formatter;
use std::sync::Arc;

use databend_common_meta_stoerr::MetaStorageError;
use databend_common_meta_types::MetaAPIError;
use databend_common_meta_types::MetaError;

use crate::exception::ErrorCodeBacktrace;
use crate::exception_backtrace::capture;
use crate::ErrorCode;
Expand Down Expand Up @@ -328,24 +324,6 @@ impl From<tonic::Status> for ErrorCode {
}
}

impl From<MetaError> for ErrorCode {
fn from(e: MetaError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}

impl From<MetaAPIError> for ErrorCode {
fn from(e: MetaAPIError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}

impl From<MetaStorageError> for ErrorCode {
fn from(e: MetaStorageError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}

impl From<ErrorCode> for tonic::Status {
fn from(err: ErrorCode) -> Self {
let error_json = serde_json::to_vec::<SerializedError>(&SerializedError {
Expand Down
1 change: 1 addition & 0 deletions src/meta/stoerr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ doctest = false
test = true

[dependencies]
databend-common-exception = { path = "../../common/exception" }

anyerror = { workspace = true }
prost = { workspace = true }
Expand Down
7 changes: 7 additions & 0 deletions src/meta/stoerr/src/meta_storage_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::fmt;
use std::io;

use anyerror::AnyError;
use databend_common_exception::ErrorCode;
use serde::Deserialize;
use serde::Serialize;
use sled::transaction::UnabortableTransactionError;
Expand Down Expand Up @@ -101,3 +102,9 @@ impl From<MetaStorageError> for io::Error {
io::Error::new(io::ErrorKind::InvalidData, e)
}
}

impl From<MetaStorageError> for ErrorCode {
fn from(e: MetaStorageError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}
1 change: 1 addition & 0 deletions src/meta/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ doctest = false
test = true

[dependencies]
databend-common-exception = { path = "../../common/exception" }
databend-common-meta-stoerr = { path = "../stoerr" }

openraft = { workspace = true }
Expand Down
7 changes: 7 additions & 0 deletions src/meta/types/src/errors/meta_api_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::fmt::Display;

use anyerror::AnyError;
use databend_common_exception::ErrorCode;
use tonic::Status;

use crate::errors;
Expand Down Expand Up @@ -202,3 +203,9 @@ impl From<RaftError<ClientWriteError>> for MetaAPIError {
}
}
}

impl From<MetaAPIError> for ErrorCode {
fn from(e: MetaAPIError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}
7 changes: 7 additions & 0 deletions src/meta/types/src/errors/meta_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_common_exception::ErrorCode;
use databend_common_meta_stoerr::MetaStorageError;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -72,3 +73,9 @@ impl From<errors::IncompleteStream> for MetaError {
Self::ClientError(client_err)
}
}

impl From<MetaError> for ErrorCode {
fn from(e: MetaError) -> Self {
ErrorCode::MetaServiceError(e.to_string())
}
}
2 changes: 1 addition & 1 deletion src/query/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ storage-hdfs = ["databend-common-storage/storage-hdfs"]
ignored = ["strum"]

[dependencies]
chrono-tz = { workspace = true }
databend-common-base = { path = "../../common/base" }
databend-common-exception = { path = "../../common/exception" }
databend-common-grpc = { path = "../../common/grpc" }
Expand All @@ -25,6 +24,7 @@ databend-common-storage = { path = "../../common/storage" }
databend-common-tracing = { path = "../../common/tracing" }
databend-common-users = { path = "../users" }

chrono-tz = { workspace = true }
clap = { workspace = true }
hex = "0.4.3"
log = { workspace = true }
Expand Down

0 comments on commit 75622f3

Please sign in to comment.