10000 [Ldap] Add LDAP error codes to exceptions by dontub · Pull Request #33339 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Ldap] Add LDAP error codes to exceptions #33339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

dontub
Copy link
@dontub dontub commented Aug 26, 2019

This PR ensures that an LdapException is only used when an LDAP
operations fails. In cases an LdapException was used for non LDAP
operations it is replaced by an appropriate exception.

Q A
Bug fix? no
New feature? yes
BC breaks? LdapException requires error code now. (I wouldn't expect it to be relevant for any component user.)
Deprecations? no
Tests pass? yes
Fixed tickets #28677
License MIT

This PR ensures that an LdapException is only used when an LDAP operations fails. The constructor of LdapException enforces that an error code is specified. In cases an LdapException was used for non LDAP operations it is replaced by an appropriate exception.

Additionally silencing is added to ldap functions where missing.

@OskarStark
Copy link
Contributor
OskarStark commented Aug 26, 2019

I like your work but to me it’s a BC break not about the error code (which could be handled and deprecated first) but someone who is catching an LdapException now got a different one and the try catch doesn’t work as expected anymore...

This could be reworked b extending LdapException by the newly introduced exceptions which would be BC.

@dontub
Copy link
Author
dontub commented Aug 27, 2019

This could be reworked b extending LdapException by the newly introduced exceptions which would be BC.

I first thought about it. Though if any of the new exceptions is thrown, the using software cannot work correctly nowadays (and I wanted to avoid extra work to fix the class hierarchy in Sf 5). Nevertheless, you are right, to completely keep the same behavior they should extend LdapException. Do you think this is necessary for DomainException as well? This one is thrown here:

throw new DomainException(sprintf('Could not search in scope "%s".', $this->options['scope']));

Though that we have a valid scope is already ensured by the OptionsResolver:
$resolver->setAllowedValues('scope', [static::SCOPE_BASE, static::SCOPE_ONE, static::SCOPE_SUB]);

@dontub
Copy link
Author
dontub commented Aug 30, 2019

BC is now ensured (apart from DomainException, see comment above). That the checks fail doesn't seem to be my fault.

Dominic Tubach added 3 commits October 9, 2019 12:46
This PR ensures that an LdapException is only used when an LDAP
operations fails. In cases an LdapException was used for non LDAP
operations it is replaced by an appropriate exception.
Style fixes
@dontub dontub force-pushed the ldap_exceptions-ticket_28677 branch from c2f96d8 to 2dede53 Compare October 9, 2019 10:47
@dontub
Copy link
Author
dontub commented Oct 9, 2019

Let me know if anything is left to change.

@nicolas-grekas nicolas-grekas changed the title [Ldap] Add LDAP error codes to exceptions #28677 [Ldap] Add LDAP error codes to exceptions Feb 4, 2020
if (false === $searchCount) {
throw new LdapException(sprintf('Error while retrieving entry count: %s.', ldap_error($con)));
throw LdapException::create('Error while retrieving entry count: [{errorCode}] {errorMsg}.', ldap_errno($con));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not doing this in Symfony, can you please revert the ::create() method?

@OskarStark
Copy link
Contributor

I would take care of this PR if we get no feedback by the author

@dontub
Copy link
Author
dontub commented Feb 4, 2020

@OskarStark I'm currently busy with other stuff, so feel free to take it up.

@OskarStark
Copy link
Contributor

Could you please add me as a collaborator to your fork?

@dontub
Copy link
Author
dontub commented Feb 5, 2020

Could you please add me as a collaborator to your fork?

Done

@fabpot
Copy link
Member
fabpot commented Mar 2, 2020

Closing in favor of #35913

@fabpot fabpot closed this Mar 2, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0