From ebae1aea930d84d11228fdd03b9b55466ad7dcb9 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Thu, 11 Jan 2024 14:02:20 +0100 Subject: [PATCH] use snafu errors (stackabletech/operator-rs#694) --- rust/operator-binary/src/discovery.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rust/operator-binary/src/discovery.rs b/rust/operator-binary/src/discovery.rs index 358d6953..664d6219 100644 --- a/rust/operator-binary/src/discovery.rs +++ b/rust/operator-binary/src/discovery.rs @@ -1,11 +1,11 @@ use std::collections::BTreeMap; use product_config::writer::to_hadoop_xml; +use snafu::{ResultExt, Snafu}; use stackable_hbase_crd::{HbaseCluster, HbaseRole, HBASE_SITE_XML}; use stackable_operator::{ - builder::{ConfigMapBuilder, ObjectMetaBuilder}, + builder::{ConfigMapBuilder, ObjectMetaBuilder, ObjectMetaBuilderError}, commons::product_image_selection::ResolvedProductImage, - error::OperatorResult, k8s_openapi::api::core::v1::ConfigMap, }; @@ -13,12 +13,25 @@ use crate::{ hbase_controller::build_recommended_labels, zookeeper::ZookeeperConnectionInformation, }; +type Result = std::result::Result; + +#[derive(Snafu, Debug)] +pub enum Error { + #[snafu(display("failed to build ConfigMap"))] + BuildConfigMap { + source: stackable_operator::error::Error, + }, + + #[snafu(display("failed to build object meta data"))] + ObjectMeta { source: ObjectMetaBuilderError }, +} + /// Creates a discovery config map containing the `hbase-site.xml` for clients. pub fn build_discovery_configmap( hbase: &HbaseCluster, zookeeper_connection_information: &ZookeeperConnectionInformation, resolved_product_image: &ResolvedProductImage, -) -> OperatorResult { +) -> Result { let hbase_site = zookeeper_connection_information.as_hbase_settings(); ConfigMapBuilder::new() @@ -32,6 +45,7 @@ pub fn build_discovery_configmap( &HbaseRole::RegionServer.to_string(), "discovery", )) + .context(ObjectMetaSnafu)? .build(), ) .add_data( @@ -45,4 +59,5 @@ pub fn build_discovery_configmap( ), ) .build() + .context(BuildConfigMapSnafu) }