From ed0a8b8e0acaf6eb402e4a8626d23c9b8b924f26 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Thu, 30 Oct 2025 20:09:56 +0000 Subject: fix: improve error message when job has 0 machines when a job is not yet in running state the program runs but the function that lists the job's machines returns zero machines which can cause a panic from division by 0 which is not a very helpful message. this commit improves the error/warn messages when no machines are listed for a job. --- src/main.rs | 4 ++++ src/oar.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6e12d6f..853c584 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1004,6 +1004,10 @@ fn machine_generate_configs( machines: &[Machine], addr_policy: &AddressAllocationPolicy, ) -> Result> { + if machines.is_empty() { + return Err(eyre::eyre!("cannot generate config for zero machines")); + } + let mut configs = Vec::default(); let mut addresses = Vec::default(); let mut address_to_index = HashMap::::default(); diff --git a/src/oar.rs b/src/oar.rs index fb73109..7f0188f 100644 --- a/src/oar.rs +++ b/src/oar.rs @@ -138,6 +138,13 @@ fn extract_machines_from_oar_stat_json(output: &str, job_id: u32) -> Result return Err(eyre::eyre!("unknown machine: '{hostname}'")), } } + + if machines.is_empty() { + tracing::warn!( + "unable to find any machines for job id {job_id}. perhaps the job is not yet in the running state?" + ); + } + Ok(machines) } -- cgit