mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-28 02:40:38 +00:00
feat: Impl ErrorExt for opaque error and ParseError
This commit is contained in:
@@ -6,5 +6,6 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
common-error = { path = "../common/error" }
|
||||
snafu = { version = "0.7", features = ["backtraces"] }
|
||||
sqlparser = "0.15.0"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use snafu::prelude::*;
|
||||
use common_error::prelude::*;
|
||||
use snafu::{prelude::*, ErrorCompat};
|
||||
use sqlparser::parser::ParserError as SpParserError;
|
||||
|
||||
/// SQL parser errors.
|
||||
@@ -29,6 +30,19 @@ pub enum ParserError {
|
||||
SpSyntax { sql: String, source: SpParserError },
|
||||
}
|
||||
|
||||
impl ErrorExt for ParserError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::Unsupported { .. } => StatusCode::Unsupported,
|
||||
Self::Unexpected { .. } | Self::SpSyntax { .. } => StatusCode::InvalidSyntax,
|
||||
}
|
||||
}
|
||||
|
||||
fn backtrace_opt(&self) -> Option<&Backtrace> {
|
||||
ErrorCompat::backtrace(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
Reference in New Issue
Block a user