Skip to content

Commit

Permalink
Remove expects when constructing Clickhouse client (zed-industries#…
Browse files Browse the repository at this point in the history
…8697)

This PR removes the `expect`s when constructing the Clickhouse client
while still retaining the less-noisy behavior from before.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Mar 2, 2024
1 parent cfe90c3 commit 486f0ae
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions crates/collab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ impl AppState {
db: Arc::new(db),
live_kit_client,
blob_store_client: build_blob_store_client(&config).await.log_err(),
clickhouse_client: build_clickhouse_client(&config),
clickhouse_client: config
.clickhouse_url
.as_ref()
.and_then(|_| build_clickhouse_client(&config).log_err()),
config,
};
Ok(Arc::new(this))
Expand Down Expand Up @@ -218,30 +221,30 @@ async fn build_blob_store_client(config: &Config) -> anyhow::Result<aws_sdk_s3::
Ok(aws_sdk_s3::Client::new(&s3_config))
}

fn build_clickhouse_client(config: &Config) -> Option<clickhouse::Client> {
let Some(url) = config.clickhouse_url.as_ref() else {
return None;
};
Some(
clickhouse::Client::default()
.with_url(url)
.with_user(
config
.clickhouse_user
.as_ref()
.expect("missing clickhouse_user"),
)
.with_password(
config
.clickhouse_password
.as_ref()
.expect("missing clickhouse_password"),
)
.with_database(
config
.clickhouse_database
.as_ref()
.expect("missing clickhouse_database"),
),
)
fn build_clickhouse_client(config: &Config) -> anyhow::Result<clickhouse::Client> {
Ok(clickhouse::Client::default()
.with_url(
config
.clickhouse_url
.as_ref()
.ok_or_else(|| anyhow!("missing clickhouse_url"))?,
)
.with_user(
config
.clickhouse_user
.as_ref()
.ok_or_else(|| anyhow!("missing clickhouse_user"))?,
)
.with_password(
config
.clickhouse_password
.as_ref()
.ok_or_else(|| anyhow!("missing clickhouse_password"))?,
)
.with_database(
config
.clickhouse_database
.as_ref()
.ok_or_else(|| anyhow!("missing clickhouse_database"))?,
))
}

0 comments on commit 486f0ae

Please sign in to comment.