technicalpickles/homesick

homesick track says "uninitialized constant Homesick::CLI::FileUtils"

dbmrq opened this issue · 6 comments

dbmrq commented

I just installed homesick on a new computer and when I run homesick track I get this error:

~ > homesick track .tlmgr.sh dotfiles
/usr/local/lib/ruby/gems/2.4.0/gems/homesick-1.1.5/lib/homesick/cli.rb:160:in `track': uninitialized constant Homesick::CLI::FileUtils (NameError)
Did you mean?  FileTest
   from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
   from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
   from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
   from /usr/local/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
   from /usr/local/lib/ruby/gems/2.4.0/gems/homesick-1.1.5/bin/homesick:9:in `<top (required)>'
   from /usr/local/bin/homesick:22:in `load'
   from /usr/local/bin/homesick:22:in `<main>'

I don't know any ruby, but I googled it a bit and added require 'FileUtils' to cli.rb.
That threw many other errors, but the track command seemed to work after all:

/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1185: warning: already initialized constant FileUtils::Entry_::S_IF_DOOR
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1185: warning: previous definition of S_IF_DOOR was here
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1443: warning: already initialized constant FileUtils::Entry_::DIRECTORY_TERM
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1443: warning: previous definition of DIRECTORY_TERM was here
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1445: warning: already initialized constant FileUtils::Entry_::SYSCASE
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1445: warning: previous definition of SYSCASE was here
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1498: warning: already initialized constant FileUtils::OPT_TABLE
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1498: warning: previous definition of OPT_TABLE was here
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1552: warning: already initialized constant FileUtils::LOW_METHODS
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1552: warning: previous definition of LOW_METHODS was here
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/fileutils.rb:1559: warning: already initialized constant FileUtils::METHODS
/usr/local/Cellar/ruby/2.4.1_1/lib/ruby/2.4.0/FileUtils.rb:1559: warning: previous definition of METHODS was here

Any ideas on what's going on? I've been using homesick for a while and this never happened before.

dbmrq commented

I googled some more and replaced require 'FileUtils' with require 'fileutils'. That seems to have fixed all the problems. I could open a pull request, but I'm not sure if there's anything else at stake here. Let me know. :)

I'm really not sure what's causing this for you. We have multiple tests around the behaviour of 'homesick track' and none of them seem to be failing. I notice in some of the stack traces above that you seem to running this on Ruby 2.4.1. AFAIK we're only testing up to 2.4.0 currently. I'll try to add 2.4.1 to the test suite when I get some time but is there any way you could install 2.4.0 and see if you get the same problem?

dbmrq commented

Ok, I think I found out where the problem is.

I tried Ruby 2.3 and it still didn't work:

~ > homesick track .tlmgr.sh dotfiles
/usr/local/lib/ruby/gems/2.3.0/gems/homesick-1.1.5/lib/homesick/cli.rb:160:in `track': uninitialized constant Homesick::CLI::FileUtils (NameError)
Did you mean?  FileTest
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	from /usr/local/lib/ruby/gems/2.3.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
	from /usr/local/lib/ruby/gems/2.3.0/gems/homesick-1.1.5/bin/homesick:9:in `<top (required)>'
	from /usr/local/bin/homesick:23:in `load'
	from /usr/local/bin/homesick:23:in `<main>'

But to to install homesick rubygems updated thor, whatever that is:

~ > gem install homesick
Successfully installed thor-0.20.0
Fetching: homesick-1.1.5.gem (100%)
Successfully installed homesick-1.1.5

So I thought maybe that's the problem. I uninstalled thor and tried it again with the previous version:

Successfully uninstalled thor-0.20.0
~ > gem install thor -v 0.19.4
Fetching: thor-0.19.4.gem (100%)
Successfully installed thor-0.19.4
Parsing documentation for thor-0.19.4
Installing ri documentation for thor-0.19.4
Done installing documentation for thor after 0 seconds
1 gem installed
~ > homesick track .tlmgr.sh dotfiles
       track  /Users/dbmrq/.homesick/repos/dotfiles/home/.tlmgr.sh already exists, and is more recent than .tlmgr.sh. Run 'homesick SYMLINK CASTLE' to create symlinks.
   identical  /Users/dbmrq/.tlmgr.sh

And it works. 🎉

So it seems the problem only happens with the thor 0.20.0 update. Like I said, adding require 'fileutils' to cli.rb fixes it, but I don't know any ruby and I don't know if that's the way to go.

Thanks for your help. :)

I get the same error with Thor 0.20.0 and Ruby 2.4.1, and can confirm that require 'fileutils' at the top of cli.rb works as a fix.

Same here with Ruby 2.4.2p198 and Thor 0.20.0.

oysta commented

It seems that this commit in Thor created this problem in homesick:

rails/thor@687337a

It was purely an accidental side effect that Thor was requiring fileutils that made it available in homesick’s cli.rb so I think the correct solution is to require it in cli.rb