mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-25 09:20:40 +00:00
refactor: Refactor usage of BoxedError (#48)
* feat: Define a general boxed error * refactor: common_function use Error in common_query * feat: Add tests to define_opaque_error macro * refactor: Refactor table and table engine error * refactor: recordbatch remove arrow dev-dependency * refactor: datanode crate use common_error::BoxedError * chore: Fix clippy * feat: Returning source status code when using BoxedError * test: Fix opaque error test * test: Add tests for table::Error & table_engine::Error * test: Add test for RecordBatch::new() * test: Remove generated tests from define_opaque_error * chore: Address cr comment
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
use std::any::Any;
|
||||
|
||||
use common_error::ext::BoxedError;
|
||||
use common_error::prelude::*;
|
||||
use datatypes::prelude::ConcreteDataType;
|
||||
use table::error::Error as TableError;
|
||||
use table_engine::error::Error as TableEngineError;
|
||||
|
||||
// TODO(dennis): use ErrorExt instead.
|
||||
pub type BoxedError = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
/// Business error of datanode.
|
||||
#[derive(Debug, Snafu)]
|
||||
#[snafu(visibility(pub))]
|
||||
@@ -27,12 +25,14 @@ pub enum Error {
|
||||
#[snafu(display("Fail to create table: {}, {}", table_name, source))]
|
||||
CreateTable {
|
||||
table_name: String,
|
||||
#[snafu(backtrace)]
|
||||
source: TableEngineError,
|
||||
},
|
||||
|
||||
#[snafu(display("Fail to get table: {}, {}", table_name, source))]
|
||||
GetTable {
|
||||
table_name: String,
|
||||
#[snafu(backtrace)]
|
||||
source: BoxedError,
|
||||
},
|
||||
|
||||
@@ -94,7 +94,7 @@ impl ErrorExt for Error {
|
||||
// TODO(yingwen): Further categorize http error.
|
||||
Error::StartHttp { .. } | Error::ParseAddr { .. } => StatusCode::Internal,
|
||||
Error::CreateTable { source, .. } => source.status_code(),
|
||||
Error::GetTable { .. } => StatusCode::Internal,
|
||||
Error::GetTable { source, .. } => source.status_code(),
|
||||
Error::TableNotFound { .. } => StatusCode::TableNotFound,
|
||||
Error::ColumnNotFound { .. } => StatusCode::TableColumnNotFound,
|
||||
Error::ColumnValuesNumberMismatch { .. }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! sql handler
|
||||
|
||||
mod insert;
|
||||
use common_error::ext::BoxedError;
|
||||
use query::catalog::schema::SchemaProviderRef;
|
||||
use query::query_engine::Output;
|
||||
use snafu::{OptionExt, ResultExt};
|
||||
@@ -34,7 +35,7 @@ impl<Engine: TableEngine> SqlHandler<Engine> {
|
||||
pub(crate) fn get_table(&self, table_name: &str) -> Result<TableRef> {
|
||||
self.table_engine
|
||||
.get_table(&EngineContext::default(), table_name)
|
||||
.map_err(|e| Box::new(e) as _)
|
||||
.map_err(BoxedError::new)
|
||||
.context(GetTableSnafu { table_name })?
|
||||
.context(TableNotFoundSnafu { table_name })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user