Skip to content

Commit 730ad76

Browse files
chore: Box error sources implicitly
1 parent 483fd97 commit 730ad76

File tree

11 files changed

+36
-37
lines changed

11 files changed

+36
-37
lines changed

rust/stackable-cockpit/src/platform/credentials.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
1111
#[derive(Debug, Snafu)]
1212
pub enum Error {
1313
#[snafu(display("failed to fetch data from Kubernetes API"))]
14-
KubeClientFetch { source: Box<k8s::Error> },
14+
KubeClientFetch {
15+
#[snafu(source(from(k8s::Error, Box::new)))]
16+
source: Box<k8s::Error>,
17+
},
1518

1619
#[snafu(display("no credentials secret found"))]
1720
NoSecret,
@@ -69,7 +72,6 @@ pub async fn get(
6972
"adminUser.password",
7073
)
7174
.await
72-
.map_err(Box::new)
7375
.context(KubeClientFetchSnafu)?
7476
}
7577
"nifi" => {
@@ -85,7 +87,6 @@ pub async fn get(
8587
"password",
8688
)
8789
.await
88-
.map_err(Box::new)
8990
.context(KubeClientFetchSnafu)?
9091
}
9192
_ => return Ok(None),

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ pub enum Error {
4949
BackgroundTask { source: JoinError },
5050

5151
#[snafu(display("failed to deploy manifests using the kube client"))]
52-
DeployManifest { source: Box<k8s::Error> },
52+
DeployManifest {
53+
#[snafu(source(from(k8s::Error, Box::new)))]
54+
source: Box<k8s::Error>,
55+
},
5356
}
5457

5558
#[derive(Clone, Debug, Deserialize, Serialize)]
@@ -195,7 +198,6 @@ impl ReleaseSpec {
195198
k8s_client
196199
.replace_crds(&crd_manifests)
197200
.await
198-
.map_err(Box::new)
199201
.context(DeployManifestSnafu)?;
200202

201203
info!("Upgraded {product_name}-operator CRDs");

rust/stackable-cockpit/src/platform/service.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use crate::utils::k8s::{self, Client, ListParamsExt};
1818
#[derive(Debug, Snafu)]
1919
pub enum Error {
2020
#[snafu(display("failed to fetch data from Kubernetes API"))]
21-
KubeClientFetch { source: Box<k8s::Error> },
21+
KubeClientFetch {
22+
#[snafu(source(from(k8s::Error, Box::new)))]
23+
source: Box<k8s::Error>,
24+
},
2225

2326
#[snafu(display("missing namespace for service {service:?}"))]
2427
MissingServiceNamespace { service: String },
@@ -62,7 +65,6 @@ pub async fn get_endpoints(
6265
}
6366
Err(err) => Err(err),
6467
}
65-
.map_err(Box::new)
6668
.context(KubeClientFetchSnafu)?;
6769

6870
let mut endpoints = IndexMap::new();
@@ -96,7 +98,6 @@ pub async fn get_endpoints(
9698
let services = client
9799
.list_services(Some(object_namespace), &list_params)
98100
.await
99-
.map_err(Box::new)
100101
.context(KubeClientFetchSnafu)?;
101102

102103
for service in services {
@@ -163,7 +164,6 @@ pub async fn get_endpoint_urls_for_nodeport(
163164
let endpoints = client
164165
.get_endpoints(service_namespace, service_name)
165166
.await
166-
.map_err(Box::new)
167167
.context(KubeClientFetchSnafu)?;
168168

169169
let node_name = match &endpoints.subsets {
@@ -291,11 +291,7 @@ async fn get_node_ip(client: &Client, node_name: &str) -> Result<String, Error>
291291
// TODO(sbernauer): Add caching. Not going to do so now, as listener-op
292292
// will replace this code entirely anyway.
293293
async fn get_node_name_ip_mapping(client: &Client) -> Result<HashMap<String, String>, Error> {
294-
let nodes = client
295-
.list_nodes()
296-
.await
297-
.map_err(Box::new)
298-
.context(KubeClientFetchSnafu)?;
294+
let nodes = client.list_nodes().await.context(KubeClientFetchSnafu)?;
299295

300296
let mut result = HashMap::new();
301297
for node in nodes {

rust/stackable-cockpit/src/platform/stacklet/grafana.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub(super) async fn list(client: &Client, namespace: Option<&str>) -> Result<Vec
1616
let services = client
1717
.list_services(namespace, &params)
1818
.await
19-
.map_err(Box::new)
2019
.context(KubeClientFetchSnafu)?;
2120

2221
for service in services {

rust/stackable-cockpit/src/platform/stacklet/minio.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(super) async fn list(client: &Client, namespace: Option<&str>) -> Result<Vec
1717
let services = client
1818
.list_services(namespace, &params)
1919
.await
20-
.map_err(Box::new)
2120
.context(KubeClientFetchSnafu)?;
2221

2322
let console_services = services

rust/stackable-cockpit/src/platform/stacklet/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ pub struct Stacklet {
4242
#[derive(Debug, Snafu)]
4343
pub enum Error {
4444
#[snafu(display("failed to create Kubernetes client"))]
45-
KubeClientCreate { source: Box<k8s::Error> },
45+
KubeClientCreate {
46+
#[snafu(source(from(k8s::Error, Box::new)))]
47+
source: Box<k8s::Error>,
48+
},
4649

4750
#[snafu(display("failed to fetch data from the Kubernetes API"))]
48-
KubeClientFetch { source: Box<k8s::Error> },
51+
KubeClientFetch {
52+
#[snafu(source(from(k8s::Error, Box::new)))]
53+
source: Box<k8s::Error>,
54+
},
4955

5056
#[snafu(display("no namespace set for custom resource {crd_name:?}"))]
5157
CustomCrdNamespace { crd_name: String },
@@ -87,7 +93,6 @@ pub async fn get_credentials_for_product(
8793
let product_cluster = match client
8894
.get_namespaced_object(namespace, object_name, &product_gvk)
8995
.await
90-
.map_err(Box::new)
9196
.context(KubeClientFetchSnafu)?
9297
{
9398
Some(obj) => obj,
@@ -125,7 +130,6 @@ async fn list_stackable_stacklets(
125130
let objects = match client
126131
.list_objects(&product_gvk, namespace)
127132
.await
128-
.map_err(Box::new)
129133
.context(KubeClientFetchSnafu)?
130134
{
131135
Some(obj) => obj,

rust/stackable-cockpit/src/platform/stacklet/opensearch.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub(super) async fn list(client: &Client, namespace: Option<&str>) -> Result<Vec
1616
let services = client
1717
.list_services(namespace, &params)
1818
.await
19-
.map_err(Box::new)
2019
.context(KubeClientFetchSnafu)?;
2120

2221
for service in services {

rust/stackable-cockpit/src/platform/stacklet/prometheus.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(super) async fn list(client: &Client, namespace: Option<&str>) -> Result<Vec
1717
let services = client
1818
.list_services(namespace, &params)
1919
.await
20-
.map_err(Box::new)
2120
.context(KubeClientFetchSnafu)?;
2221

2322
for service in services {

rust/stackablectl/src/cmds/debug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum CmdError {
3636

3737
#[snafu(display("failed to get {pod}"))]
3838
GetPod {
39+
#[snafu(source(from(kube::Error, Box::new)))]
3940
source: Box<kube::Error>,
4041
pod: ObjectRef<Pod>,
4142
},
@@ -48,13 +49,15 @@ pub enum CmdError {
4849

4950
#[snafu(display("failed to create ephemeral debug container {container:?} on {pod}"))]
5051
CreateDebugContainer {
52+
#[snafu(source(from(kube::Error, Box::new)))]
5153
source: Box<kube::Error>,
5254
pod: Box<ObjectRef<Pod>>,
5355
container: String,
5456
},
5557

5658
#[snafu(display("debug container {container:?} on {pod} never became ready"))]
5759
AwaitDebugContainerReadiness {
60+
#[snafu(source(from(kube::runtime::wait::Error, Box::new)))]
5861
source: Box<kube::runtime::wait::Error>,
5962
pod: Box<ObjectRef<Pod>>,
6063
container: String,
@@ -68,6 +71,7 @@ pub enum CmdError {
6871

6972
#[snafu(display("failed to attach to container {container:?} on {pod}"))]
7073
AttachContainer {
74+
#[snafu(source(from(kube::Error, Box::new)))]
7175
source: Box<kube::Error>,
7276
pod: Box<ObjectRef<Pod>>,
7377
container: String,
@@ -149,7 +153,6 @@ impl DebugArgs {
149153
let pod = pods
150154
.get(&self.pod)
151155
.await
152-
.map_err(Box::new)
153156
.with_context(|_| GetPodSnafu { pod: pod_ref() })?;
154157
let template_container = pod
155158
.spec
@@ -193,7 +196,6 @@ impl DebugArgs {
193196
&kube::api::Patch::Strategic(pod_patch),
194197
)
195198
.await
196-
.map_err(Box::new)
197199
.with_context(|_| CreateDebugContainerSnafu {
198200
pod: pod_ref(),
199201
container: &self.container,
@@ -214,7 +216,6 @@ impl DebugArgs {
214216
},
215217
)
216218
.await
217-
.map_err(Box::new)
218219
.with_context(|_| AwaitDebugContainerReadinessSnafu {
219220
pod: pod_ref(),
220221
container: &self.container,
@@ -244,7 +245,6 @@ impl DebugArgs {
244245
&AttachParams::interactive_tty().container(debug_container_name),
245246
)
246247
.await
247-
.map_err(Box::new)
248248
.with_context(|_| AttachContainerSnafu {
249249
pod: pod_ref(),
250250
container: &self.container,

rust/stackablectl/src/cmds/operator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ pub enum CmdError {
156156
SerializeJsonOutput { source: serde_json::Error },
157157

158158
#[snafu(display("failed to create Kubernetes client"))]
159-
KubeClientCreate { source: Box<k8s::Error> },
159+
KubeClientCreate {
160+
#[snafu(source(from(k8s::Error, Box::new)))]
161+
source: Box<k8s::Error>,
162+
},
160163

161164
#[snafu(display("failed to create namespace {namespace:?}"))]
162165
NamespaceCreate {
@@ -317,10 +320,7 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
317320
.await
318321
.context(CommonClusterArgsSnafu)?;
319322

320-
let client = Client::new()
321-
.await
322-
.map_err(Box::new)
323-
.context(KubeClientCreateSnafu)?;
323+
let client = Client::new().await.context(KubeClientCreateSnafu)?;
324324

325325
namespace::create_if_needed(&client, args.operator_namespace.clone())
326326
.await

0 commit comments

Comments
 (0)