Skip to content

Commit 7a02b94

Browse files
authored
fix: Minor improvement in error handling (#576)
Two unrelated improvements that were found while working on other features: 1. Improve the `expect` when creating the backend HTTP client. This will panic regardless, but improves the error message. 2. Log a warning when parsing the Sentry DSN fails. This makes it easier to investigate when no data turns up in Sentry.
1 parent 92d9741 commit 7a02b94

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

objectstore-server/src/observability.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ pub fn init_sentry(config: &Config) -> Option<sentry::ClientInitGuard> {
2020
let config = &config.sentry;
2121
let dsn = config.dsn.as_ref()?;
2222

23+
let dsn = match dsn.expose_secret().parse() {
24+
Ok(dsn) => Some(dsn),
25+
Err(error) => {
26+
// Sentry is initialized before the tracing subscriber, so a `warn!` here would be
27+
// dropped. Write to stderr instead to make the misconfiguration visible.
28+
eprintln!("WARN: invalid Sentry DSN, error reporting is disabled: {error}");
29+
None
30+
}
31+
};
32+
2333
let guard = sentry::init(sentry::ClientOptions {
24-
dsn: dsn.expose_secret().parse().ok(),
34+
dsn,
2535
release: Some(RELEASE.into()),
2636
environment: config.environment.clone(),
2737
server_name: config.server_name.clone(),

objectstore-service/src/backend/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,5 +278,7 @@ pub(super) fn reqwest_client() -> reqwest::Client {
278278
.no_gzip()
279279
.no_deflate()
280280
.build()
281-
.expect("Client::new()")
281+
// INVARIANT: Building fails only if the TLS backend cannot be initialized, which
282+
// is checked at startup when the rustls crypto provider is installed.
283+
.expect("failed to build backend HTTP client")
282284
}

0 commit comments

Comments
 (0)