Skip to content
This repository
Browse code

Change Standard error when is required bcrypt-ruby and fails

  • Loading branch information...
commit 7e07b7bb5da02f63d830eb70aae2835aa7d024ed 1 parent ecfdc84
Roberto Miranda robertomiranda authored

Showing 1 changed file with 7 additions and 2 deletions. Show diff stats Hide diff stats

  1. +7 2 activemodel/lib/active_model/secure_password.rb
9 activemodel/lib/active_model/secure_password.rb
@@ -43,8 +43,13 @@ def has_secure_password(options = {})
43 43 # Load bcrypt-ruby only when has_secure_password is used.
44 44 # This is to avoid ActiveModel (and by extension the entire framework)
45 45 # being dependent on a binary library.
46   - gem 'bcrypt-ruby', '~> 3.0.0'
47   - require 'bcrypt'
  46 + begin
  47 + gem 'bcrypt-ruby', '~> 3.0.0'
  48 + require 'bcrypt'
  49 + rescue LoadError => e
  50 + $stderr.puts "You don't have bcrypt-ruby installed in your application. Please add it to your Gemfile and run bundle install"
  51 + raise e
  52 + end
48 53
49 54 attr_reader :password
50 55

2 comments on commit 7e07b7b

Jeremy Kemper
Owner

This masks the original exception backtrace and outputs the true error on stderr instead of in the exception message. Instead, this should rescue the gem activation error and raise a BcryptMissing error with this message.

Better yeah, get rid of the runtime gem activation entirely. If it's the app's responsibility to provide bcrypt, then simple require bcrypt here.

Jeremy Kemper
Owner

(Looks like the re-raise was fixed in a03ab8c)

Please sign in to comment.
Something went wrong with that request. Please try again.