-
Notifications
You must be signed in to change notification settings - Fork 252
Specific errors subclassing Net::LDAP::Error #183
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
Conversation
Conflicts: lib/net/ldap.rb lib/net/ldap/filter.rb lib/net/ldap/password.rb
@@ -0,0 +1,31 @@ | |||
class Net::LDAP | |||
class Error < StandardError; end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for switching the name from LdapError
to just Error
. Does anyone have strong opinions on having a backwards compatibility placeholder?
class LdapError < Error
def message
"Deprecation warning: Net::LDAP::LdapError is no longer used. Use Net::LDAP::Error or rescue one of it's subclasses. [link to this file]\n" + super
end
end
We're pre 1.0, there's no obligation for us to do this. I'm fine with either because it's an easy error to fix if anyone runs into it and we can document it in History.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jch I support the rename and keeping around the backwards compatible constant, though the semantics of the backwards compatible constant is a bit trickier than inheriting from Error
. What needs to be backwards compatible is this:
begin
# something that could fail
rescue Net::LDAP::LdapError => error
# handle error
end
The problem with the above is that it wouldn't actually catch anything that inherits from Net::LDAP::Error
, only the specific Net::LDAP::LdapError
subclass. Instead, I think we can just have a constant assignment that would work as expected:
class Net::LDAP
class Error < StandardError; end
LdapError = Error
end
begin
rescue Net::LDAP::LdapError
# should work
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtodd good eye. What about having Error
inherit from LdapError
for a few point releases so that we can add a deprecation warning?
class Net::LDAP
class LdapError < StandardError
def message
"Deprecation warning... " + super
end
end
class Error < LdapError; end
end
This allows us to eventually remove LdapError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@satoryu nice start on this PR. Could you go over the changes and make sure that you're using the specific error when one is appropriate instead of using the generic |
when :ssha | ||
salt = SecureRandom.random_bytes(16) | ||
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp! | ||
srand; salt = (rand * 1000).to_i.to_s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 we need to continue using SecureRandom
for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @mtodd. This is also out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may indicate that your branch was behind upstream master
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss it in merging.
I think the goal should be that we don't raise |
👍 The base error class serves as a convenient catch-all for users to rescue. |
when :ssha | ||
salt = SecureRandom.random_bytes(16) | ||
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp! | ||
srand; salt = SecureRandom.random_bytes(16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@satoryu Remove this dangling srand
.
ops, Rubocop says that Net::LDAP::Connection#search offenses... |
@satoryu looks like @mynameisrufus is working on a fix here: #185 |
👍 good news. |
I merged this manually after disabling rubocop in CI. We can continue to iterate on #185, but I wanted these changes in the release I'm cutting today (0.10.2). |
@jch thanks! |
Unblocks ruby-ldap#183. There is a proposed fix in ruby-ldap#185, but it's not ready yet.
I and my colleagues are looking forward to the release of @DenisKnauf's work #61 but unfortunately there were some conflicts while he was being busy 🏃
so to take over the remaining work, I've recreated new pull request.