add main error types
This commit is contained in:
+1
-4
@@ -19,7 +19,6 @@ use std::process::{ExitCode, Termination};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use pacdef_core as core;
|
||||
use pacdef_core::{get_args, get_config_path, get_group_dir, Config, Group, Pacdef};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
@@ -32,9 +31,7 @@ fn handle_final_result(result: Result<()>) -> ExitCode {
|
||||
match result {
|
||||
Ok(_) => ExitCode::SUCCESS,
|
||||
Err(ref e) => {
|
||||
let msg = e.root_cause().to_string();
|
||||
|
||||
if msg == core::NO_PACKAGES_FOUND {
|
||||
if e.root_cause().to_string() == pacdef_core::Error::NoPackagesFound.to_string() {
|
||||
ExitCode::FAILURE
|
||||
} else {
|
||||
result.report()
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user