From dee855b6058c196eed1c6311452baacc4215ab06 Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Wed, 11 Jan 2023 13:10:05 +0100 Subject: [PATCH] add warnings for empty groups and sections --- src/group.rs | 13 +++++++++++-- src/section.rs | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/group.rs b/src/group.rs index 668f099..d203029 100644 --- a/src/group.rs +++ b/src/group.rs @@ -79,11 +79,20 @@ impl Group { let mut sections = HashSet::new(); while lines.peek().is_some() { - if let Ok(section) = Section::try_from_lines(&mut lines).context("reading section") { - sections.insert(section); + match Section::try_from_lines(&mut lines).context("reading section") { + Ok(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 }) } } diff --git a/src/section.rs b/src/section.rs index b7ac8fa..96df643 100644 --- a/src/section.rs +++ b/src/section.rs @@ -5,7 +5,7 @@ use std::{ iter::Peekable, }; -use anyhow::{Context, Result}; +use anyhow::{ensure, Context, Result}; use crate::Package; @@ -38,6 +38,9 @@ impl Section { packages.insert(package); } } + + ensure!(!packages.is_empty()); + Ok(Self::new(name, packages)) } }