mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
Lookup user/group by ID first, then by name to improve error message
`-user foo` would fail with an ugly `panic: strconv.Atoi: parsing "foo": invalid syntax` as returned by `user.LookupId()`, whereas `user.Lookup()` nicely says `panic: user: unknown user foo` In chuser() it does not matter whether we check by ID or name first, so flip the order to get sensible logs without `fmt.Errorf()` wrapping.
This commit is contained in:
parent
4a1a6144c4
commit
ad3be5a04a
1 changed files with 4 additions and 4 deletions
|
@ -22,8 +22,8 @@ func chuser(input string) error {
|
|||
uid, gid int
|
||||
)
|
||||
|
||||
if usr, err = user.Lookup(givenUser); err != nil {
|
||||
if usr, err = user.LookupId(givenUser); err != nil {
|
||||
if usr, err = user.LookupId(givenUser); err != nil {
|
||||
if usr, err = user.Lookup(givenUser); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ func chuser(input string) error {
|
|||
}
|
||||
|
||||
if givenGroup != "" {
|
||||
if grp, err = user.LookupGroup(givenGroup); err != nil {
|
||||
if grp, err = user.LookupGroupId(givenGroup); err != nil {
|
||||
if grp, err = user.LookupGroupId(givenGroup); err != nil {
|
||||
if grp, err = user.LookupGroup(givenGroup); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue