From c5e54a5dca50a2d42a1816639a8a89c58688d151 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 27 Sep 2023 18:14:57 +0200 Subject: [PATCH] client: task polling: rework code to be slightly more readable the match-arms let one follow the different branches easier than the relatively crowded if-condition it replaces. Signed-off-by: Thomas Lamprecht --- pbs-client/src/task_log.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs index ba8c85b8..d299e20e 100644 --- a/pbs-client/src/task_log.rs +++ b/pbs-client/src/task_log.rs @@ -97,12 +97,12 @@ pub async fn display_task_log( } let status_path = format!("api2/json/nodes/localhost/tasks/{upid_encoded}/status"); - let status_result = client.get(&status_path, None).await?; - if status_result["data"]["status"].as_str() == Some("stopped") { - if let Some(status) = status_result["data"]["exitstatus"].as_str() { - if status != "OK" && !status.starts_with("WARNINGS") { - bail!("task failed"); - } + let task_result = &client.get(&status_path, None).await?["data"]; + if task_result["status"].as_str() == Some("stopped") { + match task_result["exitstatus"].as_str() { + None => bail!("task stopped with unknown status"), + Some(status) if status == "OK" || status.starts_with("WARNINGS") => (), + Some(status) => bail!("task failed (status {status})"), } }