Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

More helpful error message if `thread_safe` is not available #8589

Closed
wants to merge 1 commit into from

4 participants

@Crunch09

Hi everyone,
I tried to create a new Rails project with edge rails and it responded with a not very helpful Error Message. The reason for that was, that thread_safe was required but was not available.
So i added a more helpful message, and oriented on this message which solves the same problem with thor.

rails/railties/bin/rails new testapp --edge --dev

Before

/home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- thread_safe (LoadError) from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/activesupport/lib/active_support/inflector/inflections.rb:1:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/activesupport/lib/active_support/inflector/methods.rb:3:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/activesupport/lib/active_support/dependencies/autoload.rb:1:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/activesupport/lib/active_support.rb:25:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/railties/lib/rails/generators.rb:4:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/railties/lib/rails/commands/application.rb:22:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/Code/rails/edge/rails-dev-box/rails/railties/lib/rails/cli.rb:15:in `<top (required)>'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/crunch/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from rails/railties/bin/rails:7:in `<main>'

After

The `thread_safe` gem is not available.
If you ran this command from a git checkout of Rails, please make sure it is installed,
and run this command as `ruby rails/railties/bin/rails testapp --edge --dev`
@steveklabnik
Collaborator

So, I like this idea in theory: improving error messages is always good. However, why was thread_safe not available? If we rely on it, then it should be.

@Crunch09

Don't know, it just wasn't in the list of my installed gems and i only got the error message away after i ran gem install thread_safe, same with thor afterwards.

@steveklabnik
Collaborator
@Crunch09

I just started again with a new rvm gemset, run gem update

*** LOCAL GEMS ***

bundler (1.2.3, 1.2.1)
rake (10.0.3, 10.0.0)
rubygems-bundler (1.1.0)
rvm (1.11.3.5)

executed rails/railties/bin/rails new testapp --edge --dev against the current rails master, it failed. Had to install thread_safe, thor, and i18n (hadn't noticed this one in the first place this morning, weird) by hand. Then it run through and here is the Gemfile.lock
https://gist.github.com/4360555

@steveklabnik
Collaborator

Okay, your lock shows thread_safe 0.1.0. I'm not totally convinced this is a rails bug, exactly. Hm.

@thedarkone

It wasn't available because @Crunch09 hasn't run bundle install when using rails from a freshly cloned git repository.

What actually happens is this: Rails relies on certain gems (sprockets-rails, i18n, multi_json, arel, thread_safe etc.) for its core functionality. These are listed as dependencies in Rails' various *.gemspec files, so whenever Rails is installed via rubygems its dependencies also get auto-installed. They are also included in the root Gemfile, so when you are using Rails without installing it as gem (as is in this case with a cloned git repo) a user can run bundle to have them automatically installed.

@steveklabnik
Collaborator

Right. So when actually using Rails after it's released, the bundle install happens as part of generation. So this is Not A Bug.

@Crunch09

oh ok, sorry for this, then. And thanks @thedarkone for Explaining.

@createdbypete

For anyone else that might stumble over this, I found bundle exec rails new ~/myapp --edge to make sure the bundled gems are being used not the global.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 22, 2012
  1. @Crunch09
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 activesupport/lib/active_support/inflector/inflections.rb
View
9 activesupport/lib/active_support/inflector/inflections.rb
@@ -1,4 +1,11 @@
-require 'thread_safe'
+begin
+ require 'thread_safe'
+rescue LoadError
+ puts "The `thread_safe` gem is not available.\nIf you ran this command " \
+ "from a git checkout of Rails, please make sure it is installed,\n" \
+ "and run this command as `ruby #{$0} #{(ARGV | ['--dev']).join(" ")}`"
+ exit
+end
require 'active_support/core_ext/array/prepend_and_append'
require 'active_support/i18n'
Something went wrong with that request. Please try again.