From d96a78bfb339aeb20e8a5e4ea77fd98c644dae49 Mon Sep 17 00:00:00 2001 From: Sayan Paul Date: Wed, 18 Oct 2023 09:50:43 +0000 Subject: [PATCH] error handling for non rpm-ostree system Signed-off-by: Sayan Paul --- .github/workflows/ci.yml | 4 ---- src/main.rs | 14 ++++++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8230440..af6270a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,14 +22,10 @@ jobs: skip: "./docs/Gemfile.lock,./docs/_config.yml,./.github,./.git,./greenboot.spec,./dist" fmt: - name: Cargo fmt name: Cargo fmt runs-on: ubuntu-latest container: fedora:latest steps: - - name: Install deps - run: | - dnf install -y cargo rustfmt - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: diff --git a/src/main.rs b/src/main.rs index e4abd4a..b1a8057 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ impl LogLevel { enum Commands { HealthCheck, Rollback, - Poc, + PocRollback, } /// this runs the scripts in required.d and wanted.d @@ -245,8 +245,14 @@ pub fn poc_rollback_policy(duration: u32) -> Result<()> { let s = Command::new("rpm-ostree") .arg("status") .arg("--json") - .output() - .unwrap(); + .output(); + if s.is_err() { + bail!("Unable to invoke rpm-ostree"); + } + let s = s.unwrap(); + if s.status.code() != Some(0) { + bail!("Unable to invoke rpm-ostree"); + } let j: serde_json::Value = match str::from_utf8(&s.stdout[..]) { Ok(v) => serde_json::from_str(v).unwrap(), Err(_) => bail!("cannot_convert to json"), @@ -277,7 +283,7 @@ fn main() -> Result<()> { match cli.command { Commands::HealthCheck => health_check(), Commands::Rollback => trigger_rollback(), - Commands::Poc => poc_rollback_policy(1), + Commands::PocRollback => poc_rollback_policy(1), } }