add main error types

This commit is contained in:
steven-omaha
2023-02-18 15:35:54 +01:00
parent 670f7c9850
commit 729312f8c2
4 changed files with 23 additions and 9 deletions
+19
View File
@@ -0,0 +1,19 @@
use std::fmt::Display;
/// Error types for pacdef.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// Package search yields no results.
NoPackagesFound,
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoPackagesFound => f.write_str("no packages matching query"),
}
}
}
impl std::error::Error for Error {}
+2 -1
View File
@@ -28,6 +28,7 @@ mod cmd;
mod config;
mod core;
mod env;
mod errors;
mod grouping;
mod path;
mod review;
@@ -37,9 +38,9 @@ mod ui;
pub use crate::args::get as get_args;
pub use crate::config::Config;
pub use crate::core::Pacdef;
pub use crate::errors::Error;
pub use crate::grouping::Group;
pub(crate) use crate::grouping::Package;
pub use crate::path::{get_config_path, get_group_dir};
pub use crate::search::NO_PACKAGES_FOUND;
extern crate pacdef_macros;
+1 -4
View File
@@ -8,9 +8,6 @@ use regex::Regex;
use crate::grouping::{Group, Package, Section};
/// Error message provided when a package search yields no results.
pub const NO_PACKAGES_FOUND: &str = "no packages matching query";
pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()> {
let search_string = args
.get_one::<String>("string")
@@ -31,7 +28,7 @@ pub fn search_packages(args: &ArgMatches, groups: &HashSet<Group>) -> Result<()>
}
if vec.is_empty() {
bail!(NO_PACKAGES_FOUND)
bail!(crate::errors::Error::NoPackagesFound);
}
print_triples(vec);