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

id: add error handling (stderr/exit_code) for '-ugG'

This commit is contained in:
Jan Scheer 2021-06-10 00:19:23 +02:00
parent 026570ff9c
commit 00c05b8687
2 changed files with 25 additions and 14 deletions

View file

@ -201,6 +201,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
};
let line_ending = if zflag { '\0' } else { '\n' };
let mut exit_code = 0;
if gflag {
let id = possible_pw
@ -209,13 +210,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
print!(
"{}{}",
if nflag {
entries::gid2grp(id).unwrap_or_else(|_| id.to_string())
entries::gid2grp(id).unwrap_or_else(|_| {
show_error!("cannot find name for group ID {}", id);
exit_code = 1;
id.to_string()
})
} else {
id.to_string()
},
line_ending
);
return 0;
return exit_code;
}
if uflag {
@ -225,13 +230,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
print!(
"{}{}",
if nflag {
entries::uid2usr(id).unwrap_or_else(|_| id.to_string())
entries::uid2usr(id).unwrap_or_else(|_| {
show_error!("cannot find name for user ID {}", id);
exit_code = 1;
id.to_string()
})
} else {
id.to_string()
},
line_ending
);
return 0;
return exit_code;
}
if gsflag {
@ -246,7 +255,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.unwrap_or_else(|| entries::get_groups_gnu(Some(id)).unwrap())
.iter()
.map(|&id| if nflag {
entries::gid2grp(id).unwrap_or_else(|_| id.to_string())
entries::gid2grp(id).unwrap_or_else(|_| {
show_error!("cannot find name for group ID {}", id);
exit_code = 1;
id.to_string()
})
} else {
id.to_string()
})
@ -254,7 +267,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.join(delimiter),
line_ending
);
return 0;
return exit_code;
}
if matches.is_present(options::OPT_PASSWORD) {

View file

@ -209,10 +209,9 @@ fn test_id_default_format() {
// u/g/G n/r
let args = [opt2, opt1];
let result = scene.ucmd().args(&args).run();
if !result.succeeded() && is_ci()
// && (result.stderr_str().contains("cannot find name for")
// || result.stdout_str().contains("cannot find name for"))
if !result.succeeded()
&& is_ci()
&& result.stderr_str().contains("cannot find name for")
{
// '--name' does not work on CICD ubuntu-16/ubuntu-18
// id: cannot find name for user ID 1001
@ -255,10 +254,9 @@ fn test_id_zero() {
// u/g/G n/r z
let args = [opt2, z_flag, opt1];
let result = scene.ucmd().args(&args).run();
if !result.succeeded() && is_ci()
// && (result.stderr_str().contains("cannot find name for")
// || result.stdout_str().contains("cannot find name for"))
if !result.succeeded()
&& is_ci()
&& result.stderr_str().contains("cannot find name for")
{
// '--name' does not work on CICD ubuntu-16/ubuntu-18
// id: cannot find name for user ID 1001