Skip to content

Commit

Permalink
fix: remove boilerplate message from GRPC error output (#813)
Browse files Browse the repository at this point in the history
* fix: remove boilerplate message from GRPC error output

* fix: rebase develop
  • Loading branch information
MichaelScofield authored Jan 3, 2023
1 parent 041cd42 commit f1b95e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/datanode/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl ErrorExt for Error {

impl From<Error> for tonic::Status {
fn from(err: Error) -> Self {
tonic::Status::new(tonic::Code::Internal, err.to_string())
tonic::Status::from_error(Box::new(err))
}
}

Expand Down
34 changes: 30 additions & 4 deletions src/datanode/src/instance/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use api::v1::{CreateDatabaseExpr, ObjectExpr, ObjectResult};
use std::error::Error;

use api::v1::{CreateDatabaseExpr, ObjectExpr, ObjectResult, ResultHeader};
use arrow_flight::flight_service_server::FlightService;
use arrow_flight::Ticket;
use async_trait::async_trait;
use common_error::prelude::BoxedError;
use common_error::prelude::{BoxedError, ErrorExt, StatusCode};
use common_grpc::flight;
use common_query::Output;
use prost::Message;
Expand All @@ -28,13 +30,37 @@ use table::requests::CreateDatabaseRequest;
use tonic::Request;

use crate::error::{
DecodeLogicalPlanSnafu, ExecuteSqlSnafu, FlightGetSnafu, InvalidFlightDataSnafu, Result,
DecodeLogicalPlanSnafu, Error as DatanodeError, ExecuteSqlSnafu, InvalidFlightDataSnafu, Result,
};
use crate::instance::Instance;

impl Instance {
async fn boarding(&self, ticket: Request<Ticket>) -> Result<ObjectResult> {
let response = self.do_get(ticket).await.context(FlightGetSnafu)?;
let response = self.do_get(ticket).await;
let response = match response {
Ok(response) => response,
Err(e) => {
let status_code = e
.source()
.and_then(|s| s.downcast_ref::<DatanodeError>())
.map(|s| s.status_code())
.unwrap_or(StatusCode::Internal);

let err_msg = e.source().map(|s| s.to_string()).unwrap_or(e.to_string());

// TODO(LFC): Further formalize error message when Arrow Flight adoption is done,
// and don't forget to change "test runner"'s error msg accordingly.
return Ok(ObjectResult {
header: Some(ResultHeader {
version: 1,
code: status_code as _,
err_msg,
}),
flight_data: vec![],
});
}
};

flight::flight_data_to_object_result(response)
.await
.context(InvalidFlightDataSnafu)
Expand Down

0 comments on commit f1b95e2

Please sign in to comment.