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 <slaznick@redhat.com>
This commit is contained in:
Florence Blanc-Renaud 2016-06-08 18:09:15 +02:00 committed by Martin Basti
parent aa734da494
commit 53524fbbff

View File

@ -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)