Improved error handling in LDAP module.