diff --git a/src/rust/uisp_integration/src/strategies/full/bandwidth_overrides.rs b/src/rust/uisp_integration/src/strategies/full/bandwidth_overrides.rs index a7624a6c..cfe628f3 100644 --- a/src/rust/uisp_integration/src/strategies/full/bandwidth_overrides.rs +++ b/src/rust/uisp_integration/src/strategies/full/bandwidth_overrides.rs @@ -35,9 +35,9 @@ pub fn get_site_bandwidth_overrides( continue; } let parent_node = result[0].to_string(); - if let Ok(d) = &result[1].parse::() { - if let Ok(u) = &result[2].parse::() { - overrides.insert(parent_node, (*d, *u)); + if let Some(d) = numeric_string_to_f32(&result[1]) { + if let Some(u) = numeric_string_to_f32(&result[2]) { + overrides.insert(parent_node, (d, u)); } else { error!("Cannot parse {} as float on line {line}", &result[2]); } @@ -58,6 +58,17 @@ pub fn get_site_bandwidth_overrides( Ok(HashMap::new()) } +fn numeric_string_to_f32(text: &str) -> Option { + if let Ok(n) = text.parse::() { + Some(n) + } else if let Ok(n) = text.parse::() { + Some(n as f32) + } else { + error!("Unable to parse {text} as a numeric"); + None + } +} + pub fn apply_bandwidth_overrides(sites: &mut Vec, bandwidth_overrides: &BandwidthOverrides) { for site in sites.iter_mut() { if let Some((up, down)) = bandwidth_overrides.get(&site.name) {