1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

groups: move to thiserror

This commit is contained in:
Sylvestre Ledru 2025-01-20 19:02:40 +01:00
parent 94b655c073
commit e3272a38f3
2 changed files with 8 additions and 14 deletions

View file

@ -18,6 +18,7 @@ path = "src/groups.rs"
[dependencies]
clap = { workspace = true }
thiserror = { workspace = true }
uucore = { workspace = true, features = ["entries", "process"] }
[[bin]]

View file

@ -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,