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

couldn't find HOME environment -- expanding `~' #2901

Closed
mhenrixon opened this issue Mar 1, 2016 · 3 comments
Closed

couldn't find HOME environment -- expanding `~' #2901

mhenrixon opened this issue Mar 1, 2016 · 3 comments

Comments

@mhenrixon
Copy link

Running bundle exec rubocop -D on our jenkins build server I am presented with the following:

couldn't find HOME environment -- expanding `~'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/config_loader.rb:213:in `home'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/config_loader.rb:213:in `dirs_to_search'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/config_loader.rb:201:in `config_files_in_path'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/config_loader.rb:92:in `configuration_file_for'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/config_store.rb:37:in `for'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/cli.rb:88:in `apply_default_formatter'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/lib/rubocop/cli.rb:26:in `run'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/bin/rubocop:14:in `block in <top (required)>'
/usr/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/var/lib/gems/2.1.0/gems/rubocop-0.37.0/bin/rubocop:13:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'
Build step 'Execute shell' marked build as failure
Finished: FAILURE

I really don't understand why this would be a problem.

  1. Why are you searching for my $HOME directory?
  2. Why are you crashing when you can't find one?

Just use whatever .rubocop.yml that you can in the current directory or above but please don't crash if there is no HOME configured.

Does that make sense at all?

@mikegee
Copy link
Contributor

mikegee commented Mar 2, 2016

I think this call to Dir.home is the culprit:

https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/config_loader.rb#L216

Here is some manual testing of Dir.home:

% ruby -e 'p Dir.home'
"/Users/mgee"
% HOME=foo ruby -e 'p Dir.home'
"foo"
% env -i ruby -e 'p Dir.home'
-e:1:in `home': couldn't find HOME environment -- expanding `~' (ArgumentError)
    from -e:1:in `<main>'

Some occurrences of this problem would be avoided if that code to find a config file was made lazy, only getting to HOME if a config file isn't found everywhere else first.

I suppose a more complete solution would be to guard that call Dir.home. Maybe like:

        dirs_to_search << Dir.home if ENV.key?('HOME')

@robjac
Copy link

robjac commented Dec 4, 2017

I hate commenting on closed issues but, this is the closest post to my issue

I am still seeing:

/Users/robjac/.atom/packages/linter/lib/linter-registry.js:159:

[Linter] Error running RuboCop Error: couldn't find HOME environment -- expanding `~'

/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:227:in `home'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:227:in `base_dir_for_path_parameters'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:104:in `block (2 levels) in make_excludes_absolute'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:102:in `map!'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:102:in `block in make_excludes_absolute'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:66:in `each'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:66:in `each'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config.rb:98:in `make_excludes_absolute'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config_loader.rb:50:in `load_file'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config_loader.rb:105:in `configuration_from_file'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/config_store.rb:44:in `for'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:134:in `block in process_explicit_path'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:133:in `reject'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:133:in `process_explicit_path'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:39:in `block in find'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:35:in `each'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/target_finder.rb:35:in `find'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:48:in `find_target_files'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/runner.rb:32:in `run'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cli.rb:72:in `execute_runner'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cli.rb:27:in `run'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/bin/rubocop:13:in `block in <top (required)>'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/Users/robjac/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/rubocop-0.46.0/bin/rubocop:12:in `<top (required)>'
/Users/robjac/.rbenv/versions/2.3.5/bin/rubocop:22:in `load'
/Users/robjac/.rbenv/versions/2.3.5/bin/rubocop:22:in `<main>'
    at parseFromStd (/Users/robjac/.atom/packages/linter-rubocop/src/index.js:41:43)
    at Object.<anonymous> (/Users/robjac/.atom/packages/linter-rubocop/src/index.js:221:27)
    at Generator.next (<anonymous>)
    at step (/Users/robjac/.atom/packages/linter-rubocop/src/index.js:11:273)

I've tried pointing to the rubocop found in shims (rbenv which rubocop) as well as my global (which rubocop) . Both display the same error on editor startup.

@imi24
Copy link

imi24 commented Jul 18, 2019

I have error like
couldn't find HOME environment -- expanding ~'`
for use pod command in mac after update to high sierra and i have fixed it by install rvm and permission files...

some of error fixed with

export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH

if it didnt fixed continue ...

sudo gem uninstall xcodeproj
sudo gem uninstall cocoapods

sudo su
curl -L https://get.rvm.io | bash -s stable
rvm install last

--- If rvm didnt work search and install it :-)
--- With rvm we can fixed permissions - just this :-)

rvm repair all
rvm fix-permissions
rvm get upgrade last

sudo gem install xcodeproj
sudo gem install cocoapods

and after restarting my mac I fixed my problem with pod error :-)
I hope could save your day :-)

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

No branches or pull requests

4 participants