fix: print root cause error message to user facing interface (#2486)

This commit is contained in:
LFC
2023-09-25 16:44:49 +08:00
committed by GitHub
parent f9351e4fb5
commit c0f080df26
3 changed files with 7 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ use futures::FutureExt;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use snafu::{ensure, ResultExt}; use snafu::{ensure, ErrorCompat, ResultExt};
use tokio::sync::oneshot::{self, Sender}; use tokio::sync::oneshot::{self, Sender};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tower::timeout::TimeoutLayer; use tower::timeout::TimeoutLayer;
@@ -315,7 +315,7 @@ impl JsonResponse {
}, },
Err(e) => { Err(e) => {
return Self::with_error( return Self::with_error(
format!("Query engine output error: {e}"), e.iter_chain().last().unwrap().to_string(),
e.status_code(), e.status_code(),
); );
} }

View File

@@ -26,6 +26,7 @@ use opensrv_mysql::{
}; };
use session::context::QueryContextRef; use session::context::QueryContextRef;
use snafu::prelude::*; use snafu::prelude::*;
use snafu::ErrorCompat;
use tokio::io::AsyncWrite; use tokio::io::AsyncWrite;
use crate::error::{self, Error, OtherSnafu, Result}; use crate::error::{self, Error, OtherSnafu, Result};
@@ -211,7 +212,8 @@ impl<'a, W: AsyncWrite + Unpin> MysqlResultWriter<'a, W> {
); );
let kind = ErrorKind::ER_INTERNAL_ERROR; let kind = ErrorKind::ER_INTERNAL_ERROR;
w.error(kind, error.to_string().as_bytes()).await?; let error = error.iter_chain().last().unwrap().to_string();
w.error(kind, error.as_bytes()).await?;
Ok(()) Ok(())
} }
} }

View File

@@ -31,6 +31,7 @@ use pgwire::api::{ClientInfo, Type};
use pgwire::error::{ErrorInfo, PgWireError, PgWireResult}; use pgwire::error::{ErrorInfo, PgWireError, PgWireResult};
use query::query_engine::DescribeResult; use query::query_engine::DescribeResult;
use session::Session; use session::Session;
use snafu::ErrorCompat;
use sql::dialect::PostgreSqlDialect; use sql::dialect::PostgreSqlDialect;
use sql::parser::ParserContext; use sql::parser::ParserContext;
@@ -90,7 +91,7 @@ fn output_to_query_response<'a>(
Err(e) => Ok(Response::Error(Box::new(ErrorInfo::new( Err(e) => Ok(Response::Error(Box::new(ErrorInfo::new(
"ERROR".to_string(), "ERROR".to_string(),
"XX000".to_string(), "XX000".to_string(),
e.to_string(), e.iter_chain().last().unwrap().to_string(),
)))), )))),
} }
} }