Skip to content

Commit 69c1d8a

Browse files
committed
replace expects with errors
1 parent 45ea882 commit 69c1d8a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

rust/operator-binary/src/service.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
};
55

66
use product_config::types::PropertyNameKind;
7-
use snafu::{ResultExt, Snafu};
7+
use snafu::{OptionExt, ResultExt, Snafu};
88
use stackable_operator::{
99
builder::meta::ObjectMetaBuilder,
1010
commons::product_image_selection::ResolvedProductImage,
@@ -40,6 +40,12 @@ pub enum Error {
4040
BuildLabel {
4141
source: stackable_operator::kvp::LabelError,
4242
},
43+
44+
#[snafu(display("missing zookeeper properties file {ZOOKEEPER_PROPERTIES_FILE} in config"))]
45+
MissingPropertiesFile,
46+
47+
#[snafu(display("missing provider http port key {METRICS_PROVIDER_HTTP_PORT_KEY} in config"))]
48+
MissingProviderHttpPortKey,
4349
}
4450

4551
/// The rolegroup [`Service`] is a headless service that allows internal access to the instances of a certain rolegroup
@@ -106,7 +112,7 @@ pub(crate) fn build_server_rolegroup_metrics_service(
106112
resolved_product_image: &ResolvedProductImage,
107113
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
108114
) -> Result<Service, Error> {
109-
let metrics_port = metrics_port_from_rolegroup_config(rolegroup_config);
115+
let metrics_port = metrics_port_from_rolegroup_config(rolegroup_config)?;
110116

111117
let metadata = ObjectMetaBuilder::new()
112118
.name_and_namespace(zk)
@@ -162,23 +168,25 @@ pub(crate) fn build_server_rolegroup_metrics_service(
162168

163169
pub(crate) fn metrics_port_from_rolegroup_config(
164170
rolegroup_config: &HashMap<PropertyNameKind, BTreeMap<String, String>>,
165-
) -> u16 {
171+
) -> Result<u16, Error> {
166172
let metrics_port = rolegroup_config
167173
.get(&PropertyNameKind::File(
168174
ZOOKEEPER_PROPERTIES_FILE.to_string(),
169175
))
170-
.expect("{ZOOKEEPER_PROPERTIES_FILE} is present")
176+
.context(MissingPropertiesFileSnafu)?
171177
.get(METRICS_PROVIDER_HTTP_PORT_KEY)
172-
.expect("{METRICS_PROVIDER_HTTP_PORT_KEY} is set");
178+
.context(MissingProviderHttpPortKeySnafu)?;
173179

174-
match u16::from_str(metrics_port) {
180+
let port = match u16::from_str(metrics_port) {
175181
Ok(port) => port,
176182
Err(err) => {
177183
tracing::error!("{err}");
178184
tracing::info!("Defaulting to using {METRICS_PROVIDER_HTTP_PORT} as metrics port.");
179185
METRICS_PROVIDER_HTTP_PORT
180186
}
181-
}
187+
};
188+
189+
Ok(port)
182190
}
183191

184192
/// Common labels for Prometheus

rust/operator-binary/src/zk_controller.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ pub enum Error {
293293

294294
#[snafu(display("failed to build service"))]
295295
BuildService { source: service::Error },
296+
297+
#[snafu(display("failed to retrieve metrics port from config"))]
298+
RetrieveMetricsPortFromConfig { source: service::Error },
296299
}
297300

298301
impl ReconcilerError for Error {
@@ -342,6 +345,7 @@ impl ReconcilerError for Error {
342345
Error::ListenerConfiguration { .. } => None,
343346
Error::ResolveProductImage { .. } => None,
344347
Error::BuildService { .. } => None,
348+
Error::RetrieveMetricsPortFromConfig { .. } => None,
345349
}
346350
}
347351
}
@@ -875,7 +879,9 @@ fn build_server_rolegroup_statefulset(
875879
.add_container_port(JMX_METRICS_PORT_NAME, 9505)
876880
.add_container_port(
877881
METRICS_PROVIDER_HTTP_PORT_NAME,
878-
metrics_port_from_rolegroup_config(server_config).into(),
882+
metrics_port_from_rolegroup_config(server_config)
883+
.context(RetrieveMetricsPortFromConfigSnafu)?
884+
.into(),
879885
)
880886
.add_volume_mount("data", STACKABLE_DATA_DIR)
881887
.context(AddVolumeMountSnafu)?

0 commit comments

Comments
 (0)