Skip to content

Commit

Permalink
fix: print root cause error message to user facing interface (Greptim…
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelScofield authored and paomian committed Oct 19, 2023
1 parent cb7c8d0 commit 85824a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/servers/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/servers/src/mysql/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/servers/src/postgres/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
)))),
}
}
Expand Down

0 comments on commit 85824a3

Please sign in to comment.