diff --git a/src/uu/groups/Cargo.toml b/src/uu/groups/Cargo.toml index 11055f529..51074ea2c 100644 --- a/src/uu/groups/Cargo.toml +++ b/src/uu/groups/Cargo.toml @@ -18,6 +18,7 @@ path = "src/groups.rs" [dependencies] clap = { workspace = true } +thiserror = { workspace = true } uucore = { workspace = true, features = ["entries", "process"] } [[bin]] diff --git a/src/uu/groups/src/groups.rs b/src/uu/groups/src/groups.rs index 0f0dfce80..1b28af826 100644 --- a/src/uu/groups/src/groups.rs +++ b/src/uu/groups/src/groups.rs @@ -12,8 +12,7 @@ // spell-checker:ignore (ToDO) passwd -use std::error::Error; -use std::fmt::Display; +use thiserror::Error; use uucore::{ display::Quotable, entries::{get_groups_gnu, gid2grp, Locate, Passwd}, @@ -29,26 +28,20 @@ mod options { const ABOUT: &str = help_about!("groups.md"); const USAGE: &str = help_usage!("groups.md"); -#[derive(Debug)] +#[derive(Debug, Error)] enum GroupsError { + #[error("failed to fetch groups")] GetGroupsFailed, + + #[error("cannot find name for group ID {0}")] GroupNotFound(u32), + + #[error("{user}: no such user", user = .0.quote())] UserNotFound(String), } -impl Error for GroupsError {} impl UError for GroupsError {} -impl Display for GroupsError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - Self::GetGroupsFailed => write!(f, "failed to fetch groups"), - Self::GroupNotFound(gid) => write!(f, "cannot find name for group ID {gid}"), - Self::UserNotFound(user) => write!(f, "{}: no such user", user.quote()), - } - } -} - fn infallible_gid2grp(gid: &u32) -> String { match gid2grp(*gid) { Ok(grp) => grp,