mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-30 03:40:37 +00:00
chore: Address CR comments
This commit is contained in:
@@ -20,7 +20,7 @@ macro_rules! define_opaque_error {
|
||||
/// An error behaves like `Box<dyn Error>`.
|
||||
///
|
||||
/// Define this error as a new type instead of using `Box<dyn Error>` directly so we can implement
|
||||
/// more method or trait for it.
|
||||
/// more methods or traits for it.
|
||||
pub struct $Error {
|
||||
inner: Box<dyn $crate::ext::ErrorExt + Send + Sync>,
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ impl MockError {
|
||||
|
||||
impl fmt::Display for MockError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self.code)
|
||||
write!(f, "{}", self.code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::fmt;
|
||||
|
||||
/// Common status code for public API.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum StatusCode {
|
||||
@@ -6,6 +8,8 @@ pub enum StatusCode {
|
||||
Unknown,
|
||||
/// Unsupported operation.
|
||||
Unsupported,
|
||||
/// Unexpected error, maybe there is a BUG.
|
||||
Unexpected,
|
||||
/// Internal server error.
|
||||
Internal,
|
||||
// ====== End of common status code ================
|
||||
@@ -15,8 +19,38 @@ pub enum StatusCode {
|
||||
InvalidSyntax,
|
||||
// ====== End of SQL related status code ===========
|
||||
|
||||
// ====== Begin of query related status code =======
|
||||
/// Fail to create a plan for the query.
|
||||
PlanQuery,
|
||||
/// The query engine fail to execute query.
|
||||
EngineExecuteQuery,
|
||||
// ====== End of query related status code =========
|
||||
|
||||
// ====== Begin of catalog related status code =====
|
||||
/// Table already exists.
|
||||
TableAlreadyExists,
|
||||
// ====== End of catalog related status code =======
|
||||
}
|
||||
|
||||
impl fmt::Display for StatusCode {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// The current debug format is suitable to display.
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn assert_status_code_display(code: StatusCode, msg: &str) {
|
||||
let code_msg = format!("{}", code);
|
||||
assert_eq!(msg, code_msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_display_status_code() {
|
||||
assert_status_code_display(StatusCode::Unknown, "Unknown");
|
||||
assert_status_code_display(StatusCode::TableAlreadyExists, "TableAlreadyExists");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user