From 85824a3ea509f39923653f91fa1eafdac629f37e Mon Sep 17 00:00:00 2001 From: LFC <990479+MichaelScofield@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:44:49 +0800 Subject: [PATCH] fix: print root cause error message to user facing interface (#2486) --- src/servers/src/http.rs | 4 ++-- src/servers/src/mysql/writer.rs | 4 +++- src/servers/src/postgres/handler.rs | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs index a86c3133e0e5..e599c724dcbe 100644 --- a/src/servers/src/http.rs +++ b/src/servers/src/http.rs @@ -52,7 +52,7 @@ use futures::FutureExt; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use serde_json::Value; -use snafu::{ensure, ResultExt}; +use snafu::{ensure, ErrorCompat, ResultExt}; use tokio::sync::oneshot::{self, Sender}; use tokio::sync::Mutex; use tower::timeout::TimeoutLayer; @@ -315,7 +315,7 @@ impl JsonResponse { }, Err(e) => { return Self::with_error( - format!("Query engine output error: {e}"), + e.iter_chain().last().unwrap().to_string(), e.status_code(), ); } diff --git a/src/servers/src/mysql/writer.rs b/src/servers/src/mysql/writer.rs index d5cf69703f6d..bfbb689aa869 100644 --- a/src/servers/src/mysql/writer.rs +++ b/src/servers/src/mysql/writer.rs @@ -26,6 +26,7 @@ use opensrv_mysql::{ }; use session::context::QueryContextRef; use snafu::prelude::*; +use snafu::ErrorCompat; use tokio::io::AsyncWrite; 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; - 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(()) } } diff --git a/src/servers/src/postgres/handler.rs b/src/servers/src/postgres/handler.rs index 536ca604173f..f11900133dd9 100644 --- a/src/servers/src/postgres/handler.rs +++ b/src/servers/src/postgres/handler.rs @@ -31,6 +31,7 @@ use pgwire::api::{ClientInfo, Type}; use pgwire::error::{ErrorInfo, PgWireError, PgWireResult}; use query::query_engine::DescribeResult; use session::Session; +use snafu::ErrorCompat; use sql::dialect::PostgreSqlDialect; use sql::parser::ParserContext; @@ -90,7 +91,7 @@ fn output_to_query_response<'a>( Err(e) => Ok(Response::Error(Box::new(ErrorInfo::new( "ERROR".to_string(), "XX000".to_string(), - e.to_string(), + e.iter_chain().last().unwrap().to_string(), )))), } }