aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-10-30 20:09:56 +0000
committerdiogo464 <[email protected]>2025-10-30 20:09:56 +0000
commited0a8b8e0acaf6eb402e4a8626d23c9b8b924f26 (patch)
treeafe3bbd71200467d5f3d72fb1a12dcc6700f1723
parent2bfd274bf31ed74f690bb5d4087c6a433ab83a06 (diff)
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.
-rw-r--r--src/main.rs4
-rw-r--r--src/oar.rs7
2 files changed, 11 insertions, 0 deletions
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(
1004 machines: &[Machine], 1004 machines: &[Machine],
1005 addr_policy: &AddressAllocationPolicy, 1005 addr_policy: &AddressAllocationPolicy,
1006) -> Result<Vec<MachineConfig>> { 1006) -> Result<Vec<MachineConfig>> {
1007 if machines.is_empty() {
1008 return Err(eyre::eyre!("cannot generate config for zero machines"));
1009 }
1010
1007 let mut configs = Vec::default(); 1011 let mut configs = Vec::default();
1008 let mut addresses = Vec::default(); 1012 let mut addresses = Vec::default();
1009 let mut address_to_index = HashMap::<Ipv4Addr, usize>::default(); 1013 let mut address_to_index = HashMap::<Ipv4Addr, usize>::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<Vec<
138 None => return Err(eyre::eyre!("unknown machine: '{hostname}'")), 138 None => return Err(eyre::eyre!("unknown machine: '{hostname}'")),
139 } 139 }
140 } 140 }
141
142 if machines.is_empty() {
143 tracing::warn!(
144 "unable to find any machines for job id {job_id}. perhaps the job is not yet in the running state?"
145 );
146 }
147
141 Ok(machines) 148 Ok(machines)
142} 149}
143 150