Skip to content

Commit

Permalink
chore: clean up unused errors (GreptimeTeam#2901)
Browse files Browse the repository at this point in the history
  • Loading branch information
killme2008 authored Dec 11, 2023
1 parent 6a57f49 commit cf8b6c7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 273 deletions.
214 changes: 3 additions & 211 deletions src/datanode/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +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 common_procedure::ProcedureId;
use serde_json::error::Error as JsonError;
use servers::define_into_tonic_status;
use snafu::{Location, Snafu};
use store_api::storage::RegionId;
Expand All @@ -41,24 +39,6 @@ pub enum Error {
source: common_meta::error::Error,
},

#[snafu(display("Failed to execute sql"))]
ExecuteSql {
location: Location,
source: query::error::Error,
},

#[snafu(display("Failed to plan statement"))]
PlanStatement {
location: Location,
source: query::error::Error,
},

#[snafu(display("Failed to execute statement"))]
ExecuteStatement {
location: Location,
source: query::error::Error,
},

#[snafu(display("Failed to execute logical plan"))]
ExecuteLogicalPlan {
location: Location,
Expand All @@ -80,46 +60,6 @@ pub enum Error {
#[snafu(display("Schema not found: {}", name))]
SchemaNotFound { name: String, location: Location },

#[snafu(display("Failed to create table: {}", table_name))]
CreateTable {
table_name: String,
location: Location,
source: TableError,
},

#[snafu(display("Failed to drop table {}", table_name))]
DropTable {
table_name: String,
location: Location,
source: BoxedError,
},

#[snafu(display("Table engine not found: {}", engine_name))]
TableEngineNotFound {
engine_name: String,
location: Location,
source: table::error::Error,
},

#[snafu(display("Table engine procedure not found: {}", engine_name))]
EngineProcedureNotFound {
engine_name: String,
location: Location,
source: table::error::Error,
},

#[snafu(display("Table not found: {}", table_name))]
TableNotFound {
table_name: String,
location: Location,
},

#[snafu(display("Column {} not found in table {}", column_name, table_name))]
ColumnNotFound {
column_name: String,
table_name: String,
},

#[snafu(display("Missing timestamp column in request"))]
MissingTimestampColumn { location: Location },

Expand All @@ -130,45 +70,19 @@ pub enum Error {
))]
ColumnValuesNumberMismatch { columns: usize, values: usize },

#[snafu(display("Missing insert body"))]
MissingInsertBody {
source: sql::error::Error,
location: Location,
},

#[snafu(display("Failed to insert value to table: {}", table_name))]
Insert {
table_name: String,
location: Location,
source: TableError,
},

#[snafu(display("Failed to delete value from table: {}", table_name))]
Delete {
table_name: String,
location: Location,
source: TableError,
},

#[snafu(display("Failed to flush table: {}", table_name))]
FlushTable {
table_name: String,
location: Location,
source: TableError,
},

#[snafu(display("Failed to start server"))]
StartServer {
location: Location,
source: servers::error::Error,
},

#[snafu(display("Failed to wait for GRPC serving"))]
WaitForGrpcServing {
source: servers::error::Error,
location: Location,
},

#[snafu(display("Failed to parse address {}", addr))]
ParseAddr {
addr: String,
Expand Down Expand Up @@ -224,42 +138,9 @@ pub enum Error {
#[snafu(display("Illegal primary keys definition: {}", msg))]
IllegalPrimaryKeysDef { msg: String, location: Location },

#[snafu(display(
"Constraint in CREATE TABLE statement is not supported yet: {}",
constraint
))]
ConstraintNotSupported {
constraint: String,
location: Location,
},

#[snafu(display("Failed to register a new schema"))]
RegisterSchema {
location: Location,
source: catalog::error::Error,
},

#[snafu(display("Schema {} already exists", name))]
SchemaExists { name: String, location: Location },

#[snafu(display("Failed to convert delete expr to request"))]
DeleteExprToRequest {
location: Location,
source: common_grpc_expr::error::Error,
},

#[snafu(display("Failed to parse SQL"))]
ParseSql {
location: Location,
source: sql::error::Error,
},

#[snafu(display("Failed to prepare immutable table"))]
PrepareImmutableTable {
location: Location,
source: query::error::Error,
},

#[snafu(display("Failed to access catalog"))]
Catalog {
location: Location,
Expand All @@ -272,23 +153,11 @@ pub enum Error {
source: meta_client::error::Error,
},

#[snafu(display("Failed to insert data"))]
InsertData {
location: Location,
source: common_grpc_expr::error::Error,
},

#[snafu(display(
"Table id provider not found, cannot execute SQL directly on datanode in distributed mode"
))]
TableIdProviderNotFound { location: Location },

#[snafu(display("Failed to bump table id"))]
BumpTableId {
location: Location,
source: table::error::Error,
},

#[snafu(display("Missing node id in Datanode config"))]
MissingNodeId { location: Location },

Expand All @@ -298,39 +167,12 @@ pub enum Error {
#[snafu(display("Cannot find requested database: {}-{}", catalog, schema))]
DatabaseNotFound { catalog: String, schema: String },

#[snafu(display("Failed to build default value, column: {}", column))]
ColumnDefaultValue {
column: String,
location: Location,
source: datatypes::error::Error,
},

#[snafu(display(
"No valid default value can be built automatically, column: {}",
column,
))]
ColumnNoneDefaultValue { column: String, location: Location },

#[snafu(display("Unrecognized table option"))]
UnrecognizedTableOption {
location: Location,
source: table::error::Error,
},

#[snafu(display("Failed to submit procedure {}", procedure_id))]
SubmitProcedure {
procedure_id: ProcedureId,
location: Location,
source: common_procedure::error::Error,
},

#[snafu(display("Failed to wait procedure {} done", procedure_id))]
WaitProcedure {
procedure_id: ProcedureId,
location: Location,
source: common_procedure::error::Error,
},

#[snafu(display("Failed to shutdown server"))]
ShutdownServer {
location: Location,
Expand All @@ -343,32 +185,12 @@ pub enum Error {
source: BoxedError,
},

#[snafu(display("Failed to encode object into json"))]
EncodeJson {
location: Location,
#[snafu(source)]
error: JsonError,
},

#[snafu(display("Payload not exist"))]
PayloadNotExist { location: Location },

#[snafu(display("Missing WAL dir config"))]
MissingWalDirConfig { location: Location },

#[snafu(display("Failed to join task"))]
JoinTask {
#[snafu(source)]
error: common_runtime::JoinError,
location: Location,
},

#[snafu(display("Column datatype error"))]
ColumnDataType {
location: Location,
source: api::error::Error,
},

#[snafu(display("Unexpected, violated: {}", violated))]
Unexpected {
violated: String,
Expand Down Expand Up @@ -432,32 +254,16 @@ impl ErrorExt for Error {
fn status_code(&self) -> StatusCode {
use Error::*;
match self {
ExecuteSql { source, .. }
| PlanStatement { source, .. }
| ExecuteStatement { source, .. }
| ExecuteLogicalPlan { source, .. } => source.status_code(),
ExecuteLogicalPlan { source, .. } => source.status_code(),

BuildRegionRequests { source, .. } => source.status_code(),
HandleHeartbeatResponse { source, .. } | GetMetadata { source, .. } => {
source.status_code()
}

DecodeLogicalPlan { source, .. } => source.status_code(),
RegisterSchema { source, .. } => source.status_code(),
CreateTable { source, .. } => source.status_code(),
DropTable { source, .. } => source.status_code(),
FlushTable { source, .. } => source.status_code(),

Insert { source, .. } => source.status_code(),
Delete { source, .. } => source.status_code(),
TableEngineNotFound { source, .. } | EngineProcedureNotFound { source, .. } => {
source.status_code()
}
TableNotFound { .. } => StatusCode::TableNotFound,
ColumnNotFound { .. } => StatusCode::TableColumnNotFound,

ParseSql { source, .. } => source.status_code(),
DeleteExprToRequest { source, .. } | InsertData { source, .. } => source.status_code(),

ColumnValuesNumberMismatch { .. }
| InvalidSql { .. }
Expand All @@ -467,19 +273,14 @@ impl ErrorExt for Error {
| MissingTimestampColumn { .. }
| CatalogNotFound { .. }
| SchemaNotFound { .. }
| ConstraintNotSupported { .. }
| SchemaExists { .. }
| DatabaseNotFound { .. }
| MissingNodeId { .. }
| ColumnNoneDefaultValue { .. }
| MissingWalDirConfig { .. }
| PrepareImmutableTable { .. }
| ColumnDataType { .. }
| MissingKvBackend { .. } => StatusCode::InvalidArguments,

EncodeJson { .. } | PayloadNotExist { .. } | Unexpected { .. } => {
StatusCode::Unexpected
}
PayloadNotExist { .. } | Unexpected { .. } => StatusCode::Unexpected,

// TODO(yingwen): Further categorize http error.
ParseAddr { .. }
Expand All @@ -488,18 +289,14 @@ impl ErrorExt for Error {
| Catalog { .. }
| MissingRequiredField { .. }
| IncorrectInternalState { .. }
| MissingInsertBody { .. }
| ShutdownInstance { .. }
| JoinTask { .. }
| RegionEngineNotFound { .. }
| UnsupportedOutput { .. }
| GetRegionMetadata { .. } => StatusCode::Internal,

RegionNotFound { .. } => StatusCode::RegionNotFound,

StartServer { source, .. }
| ShutdownServer { source, .. }
| WaitForGrpcServing { source, .. } => source.status_code(),
StartServer { source, .. } | ShutdownServer { source, .. } => source.status_code(),

InitBackend { .. } => StatusCode::StorageUnavailable,

Expand All @@ -509,11 +306,6 @@ impl ErrorExt for Error {
TableIdProviderNotFound { .. } | UnsupportedGrpcRequest { .. } => {
StatusCode::Unsupported
}
BumpTableId { source, .. } => source.status_code(),
ColumnDefaultValue { source, .. } => source.status_code(),
UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
SubmitProcedure { source, .. } => source.status_code(),
WaitProcedure { source, .. } => source.status_code(),
HandleRegionRequest { source, .. } => source.status_code(),
StopRegionEngine { source, .. } => source.status_code(),
}
Expand Down
Loading

0 comments on commit cf8b6c7

Please sign in to comment.