diff --git a/crates/main/main.rs b/crates/main/main.rs index a2024c6..683dd68 100644 --- a/crates/main/main.rs +++ b/crates/main/main.rs @@ -28,15 +28,16 @@ fn main() -> ExitCode { /// Skip printing the error chain when searching packages yields no results, /// otherwise report error chain. +#[allow(clippy::option_if_let_else)] fn handle_final_result(result: Result<()>) -> ExitCode { match result { Ok(_) => ExitCode::SUCCESS, Err(ref e) => { - let root_e = e.root_cause().downcast_ref(); - match root_e { - Some(pacdef_core::Error::NoPackagesFound) => ExitCode::FAILURE, - Some(_) => result.context("unknown pacdef error type").report(), - None => result.report(), + if let Some(root_error) = e.root_cause().downcast_ref::() { + eprintln!("{root_error}"); + ExitCode::FAILURE + } else { + result.report() } } } diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index 8e8dec6..cf2d02a 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -340,7 +340,7 @@ fn get_group_file_paths_matching_args<'a>( Some(group) => { result.push(group.path.as_path()); } - None => bail!("group file {} not found", file), + None => bail!(crate::errors::Error::GroupFileNotFound(file.clone())), } } diff --git a/crates/pacdef_core/src/errors.rs b/crates/pacdef_core/src/errors.rs index b3cd49d..880ffcf 100644 --- a/crates/pacdef_core/src/errors.rs +++ b/crates/pacdef_core/src/errors.rs @@ -9,6 +9,8 @@ pub enum Error { NoPackagesFound, /// Config file not found. ConfigFileNotFound, + /// Group file not found. + GroupFileNotFound(String), } impl Display for Error { @@ -16,6 +18,7 @@ impl Display for Error { match self { Self::NoPackagesFound => f.write_str("no packages matching query"), Self::ConfigFileNotFound => f.write_str("config file not found"), + Self::GroupFileNotFound(name) => f.write_str(&format!("group file '{name}' not found")), } } }