From bc0735fee76cfde975ebc354186a19745a1df404 Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Fri, 8 Sep 2023 15:32:19 +0200 Subject: [PATCH] fix #4343: updated `view_task_result` to bail on task failure Now we make an additional request on `api2/json/.../tasks/{upid}/status` to get the `exitstatus` of the task. This allows us to `bail` and thus get a non-zero exit code in the cli. Signed-off-by: Gabriel Goller --- pbs-client/src/task_log.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pbs-client/src/task_log.rs b/pbs-client/src/task_log.rs index 0bbb928d..709d0d08 100644 --- a/pbs-client/src/task_log.rs +++ b/pbs-client/src/task_log.rs @@ -96,6 +96,14 @@ 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") + && status_result["data"]["exitstatus"].as_str() != Some("OK") + { + bail!("task failed"); + } + Ok(()) };