mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
groups: move to thiserror
This commit is contained in:
parent
94b655c073
commit
e3272a38f3
2 changed files with 8 additions and 14 deletions
|
@ -18,6 +18,7 @@ path = "src/groups.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["entries", "process"] }
|
uucore = { workspace = true, features = ["entries", "process"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) passwd
|
// spell-checker:ignore (ToDO) passwd
|
||||||
|
|
||||||
use std::error::Error;
|
use thiserror::Error;
|
||||||
use std::fmt::Display;
|
|
||||||
use uucore::{
|
use uucore::{
|
||||||
display::Quotable,
|
display::Quotable,
|
||||||
entries::{get_groups_gnu, gid2grp, Locate, Passwd},
|
entries::{get_groups_gnu, gid2grp, Locate, Passwd},
|
||||||
|
@ -29,26 +28,20 @@ mod options {
|
||||||
const ABOUT: &str = help_about!("groups.md");
|
const ABOUT: &str = help_about!("groups.md");
|
||||||
const USAGE: &str = help_usage!("groups.md");
|
const USAGE: &str = help_usage!("groups.md");
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum GroupsError {
|
enum GroupsError {
|
||||||
|
#[error("failed to fetch groups")]
|
||||||
GetGroupsFailed,
|
GetGroupsFailed,
|
||||||
|
|
||||||
|
#[error("cannot find name for group ID {0}")]
|
||||||
GroupNotFound(u32),
|
GroupNotFound(u32),
|
||||||
|
|
||||||
|
#[error("{user}: no such user", user = .0.quote())]
|
||||||
UserNotFound(String),
|
UserNotFound(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for GroupsError {}
|
|
||||||
impl UError 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 {
|
fn infallible_gid2grp(gid: &u32) -> String {
|
||||||
match gid2grp(*gid) {
|
match gid2grp(*gid) {
|
||||||
Ok(grp) => grp,
|
Ok(grp) => grp,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue