]> git.proxmox.com Git - proxmox-backup.git/commitdiff
realm sync: replace formatted .context() calls
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 27 Mar 2023 09:51:17 +0000 (11:51 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 27 Mar 2023 09:51:34 +0000 (11:51 +0200)
with .map_err/.ok_or_else - since the formatting should not
happen in the non-error case

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/server/realm_sync_job.rs

index 65cb0db8319b1a86e0f8a2a1ef6b3d72c8f1ab34..1f92e843e8e6e2a514577cb21eaf9cf2eb6b3ac0 100644 (file)
@@ -1,4 +1,4 @@
-use anyhow::{bail, Context, Error};
+use anyhow::{bail, format_err, Context, Error};
 use pbs_config::{acl::AclTree, token_shadow, BackupLockGuard};
 use proxmox_lang::try_block;
 use proxmox_ldap::{Config, Connection, SearchParameters, SearchResult};
@@ -165,9 +165,11 @@ impl LdapRealmSyncJob {
                 let username = result
                     .attributes
                     .get(user_id_attribute)
-                    .context(format!(
-                        "userid attribute `{user_id_attribute}` not in LDAP search result"
-                    ))?
+                    .ok_or_else(|| {
+                        format_err!(
+                            "userid attribute `{user_id_attribute}` not in LDAP search result"
+                        )
+                    })?
                     .get(0)
                     .context("userid attribute array is empty")?
                     .clone();
@@ -176,7 +178,7 @@ impl LdapRealmSyncJob {
 
                 let userid: Userid = username
                     .parse()
-                    .context(format!("could not parse username `{username}`"))?;
+                    .map_err(|err| format_err!("could not parse username `{username}` - {err}"))?;
                 retrieved_users.insert(userid.clone());
 
                 self.create_or_update_user(user_config, &userid, result)?;