From 53524fbbff51418a8f1194c8559c9dcfcc5bbb83 Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Wed, 8 Jun 2016 18:09:15 +0200 Subject: add context to exception on LdapEntry decode error When reading the content of an invalid LDAP entry, the exception only displays the attribute name and value, but not the DN of the entry. Because of this, it is difficult to identify the root cause of the problem. The fix raises a ValueError exception which also contains the entry DN. https://fedorahosted.org/freeipa/ticket/5434 Reviewed-By: Stanislav Laznicka --- ipapython/ipaldap.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ipapython') diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 9fb7fd3f5..410ddae2c 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -308,7 +308,11 @@ class LDAPEntry(collections.MutableMapping): raw.remove(value) for value in raw_dels: - value = self._conn.decode(value, name) + try: + value = self._conn.decode(value, name) + except ValueError as e: + raise ValueError("{error} in LDAP entry '{dn}'".format( + error=e, dn=self._dn)) if value in nice_adds: continue nice.remove(value) @@ -320,7 +324,11 @@ class LDAPEntry(collections.MutableMapping): raw.append(value) for value in raw_adds: - value = self._conn.decode(value, name) + try: + value = self._conn.decode(value, name) + except ValueError as e: + raise ValueError("{error} in LDAP entry '{dn}'".format( + error=e, dn=self._dn)) if value in nice_dels: continue nice.append(value) -- cgit