chore: Address CR comments

This commit is contained in:
evenyag
2022-05-09 11:52:01 +08:00
parent d2d4d88c89
commit 5f48b4996b
7 changed files with 59 additions and 23 deletions
+34
View File
@@ -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");
}
}