refactor: Use error!(e; xxx) pattern to log error (#195)

Use `error!(e; xxx)` pattern so we could get backtrace in error log.

Also use BoxedError as error source of ExecuteQuery instead of String,
so we could carry backtrace and other info in it.
This commit is contained in:
evenyag
2022-08-23 17:35:24 +08:00
committed by GitHub
parent ad14c83369
commit 8ea2aa73cf
6 changed files with 27 additions and 29 deletions

View File

@@ -3,8 +3,9 @@ use std::{fs, path, sync::Arc};
use api::v1::{object_expr, select_expr, InsertExpr, ObjectExpr, ObjectResult, SelectExpr};
use async_trait::async_trait;
use catalog::{CatalogManagerRef, DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
use common_error::prelude::BoxedError;
use common_error::status_code::StatusCode;
use common_telemetry::logging::info;
use common_telemetry::logging::{error, info};
use common_telemetry::timer;
use log_store::fs::{config::LogConfig, log::LocalFileLogStore};
use object_store::{backend::fs::Backend, util, ObjectStore};
@@ -229,18 +230,11 @@ impl SqlQueryHandler for Instance {
let _timer = timer!(metric::METRIC_HANDLE_SQL_ELAPSED);
self.execute_sql(query)
.await
// TODO(LFC): use snafu's `context` to include source error and backtrace.
// Ideally we should define a snafu in servers::error to wrap the error thrown
// by `execute_sql`. However, we cannot do that because that would introduce a circular
// dependency.
.map_err(|e| {
servers::error::ExecuteQuerySnafu {
query,
err_msg: format!("{}", e),
}
.fail::<servers::error::Error>()
.unwrap_err()
error!(e; "Instance failed to execute sql");
BoxedError::new(e)
})
.context(servers::error::ExecuteQuerySnafu { query })
}
}