Skip to content

Commit c06c98c

Browse files
committed
chore: Handle errors properly
1 parent 238dbd8 commit c06c98c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

rust/operator-binary/src/listener.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ type Result<T, E = Error> = std::result::Result<T, E>;
1616

1717
#[derive(Snafu, Debug)]
1818
pub enum Error {
19+
#[snafu(display("Role {zk_role:?} is not defined in the ZooKeeperCluster spec"))]
20+
InvalidRole {
21+
source: crate::crd::Error,
22+
zk_role: String,
23+
},
24+
1925
#[snafu(display("object is missing metadata to build owner reference"))]
2026
ObjectMissingMetadataForOwnerRef {
2127
source: stackable_operator::builder::meta::Error,
@@ -33,11 +39,12 @@ pub fn build_role_listener(
3339
resolved_product_image: &ResolvedProductImage,
3440
zookeeper_security: &ZookeeperSecurity,
3541
) -> Result<listener::v1alpha1::Listener> {
36-
// TODO (@NickLarsenNZ): Move this to a common function that takes a zk and a zk_role so that we can use it in other places like the PVC generation
3742
let listener_name = role_listener_name(zk, zk_role);
3843
let listener_class = &zk
3944
.role(zk_role)
40-
.expect("handle error: valid role")
45+
.with_context(|_| InvalidRoleSnafu {
46+
zk_role: zk_role.to_string(),
47+
})?
4148
.role_config
4249
.listener_class;
4350

rust/operator-binary/src/zk_controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,7 @@ fn build_server_rolegroup_statefulset(
834834
&rolegroup_ref.role,
835835
&rolegroup_ref.role_group,
836836
))
837-
.expect("todo: LabelBuildSnafu");
838-
// .context(LabelBuildSnafu)?;
837+
.context(BuildLabelSnafu)?;
839838

840839
let listener_pvc = build_role_listener_pvc(
841840
&role_listener_name(zk, &ZookeeperRole::Server),
@@ -970,6 +969,7 @@ fn build_server_rolegroup_statefulset(
970969
period_seconds: Some(1),
971970
..Probe::default()
972971
})
972+
// TODO (@NickLarsenNZ): Use consts for the port names (since they are used in multiple places)
973973
.add_container_port("zk", zookeeper_security.client_port().into())
974974
.add_container_port("zk-leader", ZOOKEEPER_LEADER_PORT as i32)
975975
.add_container_port("zk-election", ZOOKEEPER_ELECTION_PORT as i32)

rust/operator-binary/src/znode_controller.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ async fn reconcile_apply(
274274
&znode.object_ref(&()),
275275
ClusterResourceApplyStrategy::from(&zk.spec.cluster_operation),
276276
)
277+
// TODO (@NickLarsenNZ): Handle this error properly. znode should contain namespace/name, but there is no guarantee
277278
.unwrap();
278279

279280
znode_mgmt::ensure_znode_exists(

0 commit comments

Comments
 (0)