Fix some error handling

This commit is contained in:
Alexandr Bogomyakov
2023-07-31 12:10:36 +03:00
parent ad2d36bb35
commit c635ed0dd0
3 changed files with 17 additions and 5 deletions

View File

@ -91,8 +91,14 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('[')) {
let r = r.clone();
let start = r.find('[').unwrap();
let end = r.find(']').unwrap();
let start = r.find(']').unwrap();
let end = match r.find(']') {
None => {
error!("Error parsing host expression. Wrong range expansion '[a:b]'");
process::exit(1);
}
Some(s) => s
};
let colon = r.find(':').unwrap();
let low = r[start+1..colon].parse::<i32>().unwrap();
let high = r[colon+1..end].parse::<i32>().unwrap();
@ -106,7 +112,13 @@ fn expand_string(s: &str) -> Vec<Host> {
while let Some(r) = result.iter().find(|s| s.contains('{')) {
let r = r.clone();
let start = r.find('{').unwrap();
let end = r.find('}').unwrap();
let end = match r.find('}') {
None => {
error!("Error parsing host expression. Wrong range expansion '{{one,two}}'");
process::exit(1);
}
Some(s) => s
};
let list = &r[start+1..end];
result.retain(|s| s != &r);
for val in expand_list(list) {