Skip to content

Commit

Permalink
refactor: log statement on error by Display
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Apr 25, 2024
1 parent 1ec5951 commit 80c818b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
8 changes: 3 additions & 5 deletions src/frontend/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,18 @@ impl SqlQueryHandler for Instance {
break;
}

match self.query_statement(stmt, query_ctx.clone()).await {
match self.query_statement(stmt.clone(), query_ctx.clone()).await {
Ok(output) => {
let output_result =
query_interceptor.post_execute(output, query_ctx.clone());
results.push(output_result);
}
Err(e) => {
let redacted = sql::util::redact_sql_secrets(query.as_ref());
if e.status_code().should_log_error() {
error!(e; "Failed to execute query: {redacted}");
error!(e; "Failed to execute query: {stmt}");
} else {
debug!("Failed to execute query: {redacted}, {e}");
debug!("Failed to execute query: {stmt}, {e}");
}

results.push(Err(e));
break;
}
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/src/instance/prom_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ impl Instance {
.handle_remote_query(&ctx, catalog_name, schema_name, &table_name, query)
.await
.map_err(BoxedError::new)
.with_context(|_| error::ExecuteQuerySnafu {
query: format!("{query:#?}"),
})?;
.with_context(|_| error::ExecuteQuerySnafu)?;

results.push((table_name, output));
}
Expand Down
3 changes: 1 addition & 2 deletions src/servers/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ pub enum Error {
error: Box<dyn std::error::Error + Send + Sync>,
},

#[snafu(display("Failed to execute query, query: {}", query))]
#[snafu(display("Failed to execute query"))]
ExecuteQuery {
query: String,
location: Location,
source: BoxedError,
},
Expand Down
13 changes: 3 additions & 10 deletions src/servers/src/query_handler/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ where
.do_query(query, query_ctx)
.await
.into_iter()
.map(|x| {
x.map_err(BoxedError::new)
.context(error::ExecuteQuerySnafu { query })
})
.map(|x| x.map_err(BoxedError::new).context(error::ExecuteQuerySnafu))
.collect()
}

Expand All @@ -109,12 +106,8 @@ where
.await
.into_iter()
.map(|x| {
x.map_err(BoxedError::new).with_context(|_| {
let query_literal = format!("{query:?}");
error::ExecuteQuerySnafu {
query: query_literal,
}
})
x.map_err(BoxedError::new)
.with_context(|_| error::ExecuteQuerySnafu)
})
.collect()
}
Expand Down

0 comments on commit 80c818b

Please sign in to comment.