Skip to content

Commit

Permalink
fix(task): Improve error message when become fails
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Gil <[email protected]>
  • Loading branch information
pando85 committed Sep 4, 2023
1 parent c6881b9 commit 1c49370
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions rash_core/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,22 @@ impl Task {

match self.r#become {
true => {
let user = match User::from_name(&self.become_user)? {
let user_not_found_error = || {
Error::new(
ErrorKind::Other,
format!("User {:?} not found.", self.become_user),
)
};
let user = match User::from_name(&self.become_user)
.map_err(|_| user_not_found_error())?
{
Some(user) => Ok(user),
None => match self.become_user.parse::<u32>().map(Uid::from_raw) {
Ok(uid) => match User::from_uid(uid)? {
Some(user) => Ok(user),
None => Err(Error::new(
ErrorKind::NotFound,
format!("user: {} not found", &self.become_user),
)),
None => Err(user_not_found_error()),
},
Err(e) => Err(Error::new(ErrorKind::Other, e)),
Err(_) => Err(user_not_found_error()),
},
}?;

Expand Down

0 comments on commit 1c49370

Please sign in to comment.