add warnings for empty groups and sections

This commit is contained in:
timeshifter
2023-01-11 13:10:05 +01:00
parent 8f4cd91c03
commit 3088957e04
2 changed files with 15 additions and 3 deletions
+10 -1
View File
@@ -79,9 +79,18 @@ impl Group {
let mut sections = HashSet::new(); let mut sections = HashSet::new();
while lines.peek().is_some() { while lines.peek().is_some() {
if let Ok(section) = Section::try_from_lines(&mut lines).context("reading section") { match Section::try_from_lines(&mut lines).context("reading section") {
Ok(section) => {
sections.insert(section); sections.insert(section);
} }
Err(e) => {
println!("WARNING: could not process a section under group '{name}': {e:?}\n")
}
}
}
if sections.is_empty() {
println!("WARNING: no sections found in group '{name}'");
} }
Ok(Self { name, sections }) Ok(Self { name, sections })
+4 -1
View File
@@ -5,7 +5,7 @@ use std::{
iter::Peekable, iter::Peekable,
}; };
use anyhow::{Context, Result}; use anyhow::{ensure, Context, Result};
use crate::Package; use crate::Package;
@@ -38,6 +38,9 @@ impl Section {
packages.insert(package); packages.insert(package);
} }
} }
ensure!(!packages.is_empty());
Ok(Self::new(name, packages)) Ok(Self::new(name, packages))
} }
} }