Skip to content

Commit 042689f

Browse files
committed
Improve snafu error messages
1 parent e43e373 commit 042689f

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

trino-lb/src/http_server/admin/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use trino_lb_persistence::Persistence;
2121

2222
use crate::{
2323
cluster_group_manager::{self, ClusterStats},
24+
error_formatting::snafu_error_to_string,
2425
http_server::AppState,
2526
};
2627

@@ -71,7 +72,7 @@ impl IntoResponse for Error {
7172
Error::GetQueryCounterForGroup { .. } => StatusCode::INTERNAL_SERVER_ERROR,
7273
Error::GetAllClusterStates { .. } => StatusCode::INTERNAL_SERVER_ERROR,
7374
};
74-
(status_code, format!("{self}")).into_response()
75+
(status_code, snafu_error_to_string(&self)).into_response()
7576
}
7677
}
7778

trino-lb/src/http_server/metrics.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use prometheus::{Encoder, TextEncoder};
99
use snafu::{ResultExt, Snafu};
1010
use tracing::{instrument, warn};
1111

12-
use crate::http_server::AppState;
12+
use crate::{error_formatting::snafu_error_to_string, http_server::AppState};
1313

1414
#[derive(Snafu, Debug)]
1515
pub enum Error {
@@ -23,7 +23,11 @@ pub enum Error {
2323
impl IntoResponse for Error {
2424
fn into_response(self) -> Response {
2525
warn!(error = ?self, "Error while processing metrics request");
26-
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self:?}")).into_response()
26+
(
27+
StatusCode::INTERNAL_SERVER_ERROR,
28+
snafu_error_to_string(&self),
29+
)
30+
.into_response()
2731
}
2832
}
2933

trino-lb/src/http_server/ui/index.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use tracing::{instrument, warn};
1212

1313
use crate::{
1414
cluster_group_manager::{self, ClusterStats},
15+
error_formatting::snafu_error_to_string,
1516
http_server::AppState,
1617
};
1718

@@ -33,7 +34,7 @@ impl IntoResponse for Error {
3334
Error::GetAllClusterStates { .. } => StatusCode::INTERNAL_SERVER_ERROR,
3435
Error::RenderTemplate { .. } => StatusCode::INTERNAL_SERVER_ERROR,
3536
};
36-
(status_code, format!("{self}")).into_response()
37+
(status_code, snafu_error_to_string(&self)).into_response()
3738
}
3839
}
3940

trino-lb/src/http_server/ui/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use tracing::{instrument, warn};
1111
use trino_lb_core::TrinoLbQueryId;
1212
use trino_lb_persistence::Persistence;
1313

14-
use crate::http_server::AppState;
14+
use crate::{error_formatting::snafu_error_to_string, http_server::AppState};
1515

1616
#[derive(Snafu, Debug)]
1717
pub enum Error {
@@ -36,7 +36,7 @@ impl IntoResponse for Error {
3636
Error::QueryIdMissing => StatusCode::BAD_REQUEST,
3737
Error::QueryIdNotFound { .. } => StatusCode::NOT_FOUND,
3838
};
39-
(status_code, format!("{self}")).into_response()
39+
(status_code, snafu_error_to_string(&self)).into_response()
4040
}
4141
}
4242

trino-lb/src/http_server/v1/statement.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use url::Url;
2828

2929
use crate::{
3030
cluster_group_manager::{self, SendToTrinoResponse},
31+
error_formatting::snafu_error_to_string,
3132
http_server::AppState,
3233
maintenance::leftover_queries::UPDATE_QUEUED_QUERY_LAST_ACCESSED_INTERVAL,
3334
};
@@ -131,7 +132,11 @@ pub enum Error {
131132
impl IntoResponse for Error {
132133
fn into_response(self) -> Response {
133134
warn!(error = ?self, "Error while processing request");
134-
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self:?}")).into_response()
135+
(
136+
StatusCode::INTERNAL_SERVER_ERROR,
137+
snafu_error_to_string(&self),
138+
)
139+
.into_response()
135140
}
136141
}
137142

trino-lb/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::{args::Args, http_server::start_http_server};
2323

2424
mod args;
2525
mod cluster_group_manager;
26+
mod error_formatting;
2627
mod http_server;
2728
mod maintenance;
2829
mod metrics;

0 commit comments

Comments
 (0)