Skip to content
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

ENV["HOME"] default may throw fatal NoMethodError on *NIX #8

Open
pilcrow opened this issue Aug 26, 2009 · 8 comments
Open

ENV["HOME"] default may throw fatal NoMethodError on *NIX #8

pilcrow opened this issue Aug 26, 2009 · 8 comments

Comments

@pilcrow
Copy link

pilcrow commented Aug 26, 2009

The default catenation of two (Windows-specific?) ENV vars on line 1089 of rbreadline.rb results in a fatal NoMethodError (NilClass +) on a *NIX system if $HOME is not set. Further, even if it were to succeed, the library has now modified a process-level attribute, and the new ENV var will be inherited by any children spawned by the rb-readline-require'ing script.

While $HOME-less environments aren't common in *NIX, they do occur, and rb-readline should not give a fatal error nor permanently muck with the environment when they do.

@luislavena
Copy link
Collaborator

Thank you for the report pilcrow

Can you propose a patch?

Right now the system defines HOME to be able to expand and locate inputrc and history files in the user home directory.

Regards.

@rdp
Copy link
Contributor

rdp commented Oct 6, 2009

Perhaps
File.expand_path '~' would help

@Spakman
Copy link
Collaborator

Spakman commented May 22, 2011

@rdp - I think that File.expand_path("~") uses ENV["HOME"].

Kind of thinking out loud - perhaps we could print something to STDERR if rb-readline tries to tilde expand without ENV["HOME"] being set? Is there anything obviously wrong with that approach?

@mdarby
Copy link

mdarby commented Apr 19, 2013

I just ran into this issue myself while running a rake task through god on Ubuntu. I set ENV["HOME"] = <home directory> and all worked as expected.

Not to nitpick, but a raised error when the ENV["HOME"] var is empty would help.

@qichunren
Copy link

I also got this problem:
https://github.com/luislavena/rb-readline/blob/master/lib/rbreadline.rb#L1093
ENV["HOME"] ||= ENV["HOMEDRIVE"]+ENV["HOMEPATH"]

<module:RbReadline>': undefined method+' for nil:NilClass (NoMethodError)

@njvack
Copy link
Contributor

njvack commented Jun 5, 2013

If I don't have ENV['HOME'] set, it's a pretty good bet that I don't care about history or inputrc.

I'd propose:

ENV['HOME'] ||= "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"

which would defer whatever evils may come from not having a home directory until later. If that might cause Evil, follow it up with:

if !File.directory? ENV['HOME']
  raise RuntimeError.new("The HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory")
end

Yes, I just spent a day trying to figure out a deployment issue that stemmed from this, too.

@Spakman
Copy link
Collaborator

Spakman commented Aug 21, 2013

I've left this open, as I would like to see us not require these variables at all.

However, this is a definite improvement - thanks, @njvack :)!

robbkidd added a commit to chef/supermarket that referenced this issue Jul 27, 2016
Our calls to `bundle exec` in the omnibus install need to have a HOME set
because of an updated rb-readline that requires it.[1] This is related to
28345e92, where a HOME was added to the runit startup scripts for rails
and sidekiq. This is the only other `bundle exec` in the omnibus cookbook
and so it needs a HOME, too.

[1] ConnorAtherton/rb-readline#8

Signed-off-by: Robb Kidd <rkidd@chef.io>
@theasteve
Copy link

I am also having issues when deploying a Rails 5 app to AWS using elastic beanstalk, I get the following output in the logs:


Application update failed at 2017-10-24T19:27:36Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed.

    ++ /opt/elasticbeanstalk/bin/get-config container -k script_dir
    + EB_SCRIPT_DIR=/opt/elasticbeanstalk/support/scripts
    ++ /opt/elasticbeanstalk/bin/get-config container -k app_staging_dir
    + EB_APP_STAGING_DIR=/var/app/ondeck
    ++ /opt/elasticbeanstalk/bin/get-config container -k app_user
    + EB_APP_USER=webapp
    ++ /opt/elasticbeanstalk/bin/get-config container -k support_dir
    + EB_SUPPORT_DIR=/opt/elasticbeanstalk/support
    + . /opt/elasticbeanstalk/support/envvars
    ++ export RACK_ENV=production
    ++ RACK_ENV=production
    ++ export RAILS_SKIP_ASSET_COMPILATION=false
    ++ RAILS_SKIP_ASSET_COMPILATION=false
    ++ export RAILS_SKIP_MIGRATIONS=false
    ++ RAILS_SKIP_MIGRATIONS=false
    ++ export BUNDLE_WITHOUT=test:development
    ++ BUNDLE_WITHOUT=test:development
    ++ export RDS_PORT=5432
    ++ RDS_PORT=5432
    ++ export RDS_HOSTNAME=aa16lalntiz6vr0.cghvpjf0tzo5.us-east-1.rds.amazonaws.com
    ++ RDS_HOSTNAME=aa16lalntiz6vr0.cghvpjf0tzo5.us-east-1.rds.amazonaws.com
    ++ export RDS_USERNAME=theasteve
    ++ RDS_USERNAME=theasteve
    ++ export RDS_DB_NAME=ebdb
    ++ RDS_DB_NAME=ebdb
    ++ export RDS_PASSWORD=Colombia1
    ++ RDS_PASSWORD=Colombia1
    + RAKE_TASK=assets:precompile
    + . /opt/elasticbeanstalk/support/scripts/use-app-ruby.sh
    ++ . /usr/local/share/chruby/chruby.sh
    +++ CHRUBY_VERSION=0.3.9
    +++ RUBIES=()
    +++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
    +++ [[ -d /opt/rubies ]]
    ++++ ls -A /opt/rubies
    +++ [[ -n ruby-1.9.3-p551
    ruby-2.0.0-p648
    ruby-2.1.10
    ruby-2.2.8
    ruby-2.3.5
    ruby-2.4.2
    ruby-current ]]
    +++ RUBIES+=("$dir"/*)
    +++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
    +++ [[ -d /.rubies ]]
    +++ unset dir
    +++ cat /etc/elasticbeanstalk/.ruby_version
    ++ chruby 2.3.5
    ++ case "$1" in
    ++ local dir match
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-1.9.3-p551
    ++ case "${dir##*/}" in
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-2.0.0-p648
    ++ case "${dir##*/}" in
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-2.1.10
    ++ case "${dir##*/}" in
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-2.2.8
    ++ case "${dir##*/}" in
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-2.3.5
    ++ case "${dir##*/}" in
    ++ match=/opt/rubies/ruby-2.3.5
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-2.4.2
    ++ case "${dir##*/}" in
    ++ for dir in '"${RUBIES[@]}"'
    ++ dir=/opt/rubies/ruby-current
    ++ case "${dir##*/}" in
    ++ [[ -z /opt/rubies/ruby-2.3.5 ]]
    ++ shift
    ++ chruby_use /opt/rubies/ruby-2.3.5 ''
    ++ [[ ! -x /opt/rubies/ruby-2.3.5/bin/ruby ]]
    ++ [[ -n '' ]]
    ++ export RUBY_ROOT=/opt/rubies/ruby-2.3.5
    ++ RUBY_ROOT=/opt/rubies/ruby-2.3.5
    ++ export RUBYOPT=
    ++ RUBYOPT=
    ++ export PATH=/opt/rubies/ruby-2.3.5/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
    ++ PATH=/opt/rubies/ruby-2.3.5/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
    +++ /opt/rubies/ruby-2.3.5/bin/ruby -
    ++ eval 'export RUBY_ENGINE=ruby;
    export RUBY_VERSION=2.3.5;
    export GEM_ROOT="/opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0";'
    +++ export RUBY_ENGINE=ruby
    +++ RUBY_ENGINE=ruby
    +++ export RUBY_VERSION=2.3.5
    +++ RUBY_VERSION=2.3.5
    +++ export GEM_ROOT=/opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0
    +++ GEM_ROOT=/opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0
    ++ (( 0 != 0 ))
    + cd /var/app/ondeck
    + su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
    `/home/webapp` is not a directory.
    Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
    + '[' false == true ']'
    + su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
    `/home/webapp` is not a directory.
    Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
    rake aborted!
    Bundler::GemRequireError: There was an error while trying to load the gem 'rb-readline'.
    Gem Load Error is: HOME environment variable (or HOMEDRIVE and HOMEPATH) must be set and point to a directory
    Backtrace for gem load error is:
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/rbreadline.rb:1097:in `<module:RbReadline>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/rbreadline.rb:17:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/readline.rb:10:in `require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/readline.rb:10:in `<module:Readline>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/readline.rb:8:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/rb-readline.rb:16:in `require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rb-readline-0.5.4/lib/rb-readline.rb:16:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:82:in `require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:77:in `each'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:77:in `block in require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:66:in `each'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/runtime.rb:66:in `require'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler.rb:108:in `require'
    /var/app/ondeck/config/application.rb:17:in `<top (required)>'
    /var/app/ondeck/Rakefile:4:in `require_relative'
    /var/app/ondeck/Rakefile:4:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in `load_rakefile'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:687:in `raw_load_rakefile'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:96:in `block in load_rakefile'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:95:in `load_rakefile'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:79:in `block in run'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/bin/rake:23:in `load'
    /opt/rubies/ruby-2.3.5/bin/rake:23:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli/exec.rb:74:in `load'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli/exec.rb:74:in `kernel_load'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli/exec.rb:27:in `run'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli.rb:360:in `exec'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli.rb:20:in `dispatch'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/cli.rb:10:in `start'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/exe/bundle:35:in `block in <top (required)>'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
    /opt/rubies/ruby-2.3.5/lib/ruby/gems/2.3.0/gems/bundler-1.15.0/exe/bundle:27:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/bin/bundle:23:in `load'
    /opt/rubies/ruby-2.3.5/bin/bundle:23:in `<main>'
    Bundler Error Backtrace:
    /var/app/ondeck/config/application.rb:17:in `<top (required)>'
    /var/app/ondeck/Rakefile:4:in `require_relative'
    /var/app/ondeck/Rakefile:4:in `<top (required)>'
    /opt/rubies/ruby-2.3.5/bin/bundle:23:in `load'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants