Skip to content

BCrypt::Errors::* descend from new BCrypt::Error.#51

Merged
tmm1 merged 2 commits into
bcrypt-ruby:masterfrom
pda:bcrypt_error
Mar 31, 2013
Merged

BCrypt::Errors::* descend from new BCrypt::Error.#51
tmm1 merged 2 commits into
bcrypt-ruby:masterfrom
pda:bcrypt_error

Conversation

@pda
Copy link
Copy Markdown
Contributor

@pda pda commented Sep 28, 2012

The addition of a root BCrypt::Error class makes error handling far less verbose, and does not impact backwards compatibility. It also means code which rescues BCrypt::Error today will handle BCrypt::Errors::InvalidMoonPhase if it's added in future.

Before

begin
  # some BCrypt call
rescue BCrypt::Errors::InvalidSalt, BCrypt::Errors::InvalidHash,
       BCrypt::Errors::InvalidCost, BCrypt::Errors::InvalidSecret
  # handle error
end

After

begin
  # ...
rescue BCrypt::Error
  # ...
end

RSpec output:

Errors
  BCrypt::Error
    can be rescued as a StandardError
  BCrypt::Errors::InvalidCost
    can be rescued as a BCrypt::Error
  BCrypt::Errors::InvalidHash
    can be rescued as a BCrypt::Error
  BCrypt::Errors::InvalidSalt
    can be rescued as a BCrypt::Error
  BCrypt::Errors::InvalidSecret
    can be rescued as a BCrypt::Error

pda added 2 commits September 28, 2012 14:59
This makes error handling far easier, and does not impact backwards
compatibility.

This is now possible:

    begin
      # some BCrypt call
    rescue BCrypt::Error
      # handle error
    end

Instead of:

    begin
      # some BCrypt call
    rescue BCrypt::Errors::InvalidSalt, BCrypt::Errors::InvalidHash, BCrypt::Errors::InvalidCost, BCrypt::Errors::InvalidSecret
      # handle error
    end

RSpec output:

    Errors
      BCrypt::Error
        can be rescued as a StandardError
      BCrypt::Errors::InvalidCost
        can be rescued as a BCrypt::Error
      BCrypt::Errors::InvalidHash
        can be rescued as a BCrypt::Error
      BCrypt::Errors::InvalidSalt
        can be rescued as a BCrypt::Error
      BCrypt::Errors::InvalidSecret
        can be rescued as a BCrypt::Error
tmm1 added a commit that referenced this pull request Mar 31, 2013
BCrypt::Errors::* descend from new BCrypt::Error.
@tmm1 tmm1 merged commit d2dceb8 into bcrypt-ruby:master Mar 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants