[pbs-devel] [PATCH backup 4/4] api: use if-let pattern for error-only handling

Fabian Grünbichler f.gruenbichler at proxmox.com
Tue Feb 13 11:26:38 CET 2024


On February 13, 2024 10:53 am, Maximiliano Sandoval wrote:
> It is more readable than using match. We also inline variables in
> eprintln!.

what about the exact same pattern directly above it? there's like 10
more places to look at based on simple grepping..

> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
> ---
>  src/api2/access/user.rs | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/src/api2/access/user.rs b/src/api2/access/user.rs
> index 118838ce..035c8a57 100644
> --- a/src/api2/access/user.rs
> +++ b/src/api2/access/user.rs
> @@ -391,18 +391,12 @@ pub fn delete_user(userid: Userid, digest: Option<String>) -> Result<(), Error>
>          }
>      }
>  
> -    match crate::config::tfa::read().and_then(|mut cfg| {
> +    if let Err(err) = crate::config::tfa::read().and_then(|mut cfg| {
>          let _: proxmox_tfa::api::NeedsSaving =
>              cfg.remove_user(&crate::config::tfa::UserAccess, userid.as_str())?;
>          crate::config::tfa::write(&cfg)
>      }) {
> -        Ok(()) => (),
> -        Err(err) => {
> -            eprintln!(
> -                "error updating TFA config after deleting user {:?}: {}",
> -                userid, err
> -            );
> -        }
> +        eprintln!("error updating TFA config after deleting user {userid:?} {err}",);
>      }
>  
>      Ok(())
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel at lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 
> 




More information about the pbs-devel mailing list