Search code examples
rubybuildrubygemsraketravis-ci

Travis CI Build Failure: The command "bundle exec rake" exited with 1


Very new to Travis CI. Build failed with The command "bundle exec rake" exited with 1.

The build was passing before my latest changes which involved using Fileutils to write to gem directory so I'm assuming this is the culprit.

I found this : https://stackoverflow.com/a/40643667/9526393 but still no luck

Any ideas?

Build: https://travis-ci.org/AlphaDaniel/ruby_doc/builds/356485701?utm_source=github_status&utm_medium=notification

Repo: https://github.com/AlphaDaniel/ruby_doc

    rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
Errno::ENOENT: No such file or directory @ utime_internal - /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt
/home/travis/build/AlphaDaniel/ruby_doc/config/environment.rb:23:in `<top (required)>'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `require_relative'
/home/travis/build/AlphaDaniel/ruby_doc/Rakefile:5:in `<top (required)>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:30:in `block in <main>'
/home/travis/.rvm/rubies/ruby-2.2.3/bin/bundle:22:in `<main>'
(See full trace by running task with --trace)

Solution

  • The problem here becomes more clear if you read the error message and the stack trace. Errno::ENOENT: No such file or directory basically means that Ruby can not find a specific file or directory, in your case it's /home/travis/build/AlphaDaniel/ruby_doc/vendor/bundle/ruby/2.2.0/gems/ruby_doc-2.2.0/favs.txt. The last line of code that ran is a call to FileUtils.touch (in config/environment.rb:23).

    You may have asked yourself "But shouldn't that create this file if it does not yet exist?". The answer to that is: yes, however only when the parent directories exist as well. When you gem install your gem, those directories will be created for you. This is not the case when you clone your repository and run rake (which is also what Travis automatically does for you when it sees a Ruby project).

    To solve that, I recommend you to change the fav_dir method's body to something like this:

    File.expand_path("../favs.txt", __dir__)
    

    Looks a bit magic at first glance, but it isn't really: __dir__ is a Ruby method which returns the absolute path of the directory of the file from which this method is called. In this case this would be e.g. /usr/home/foo/dev/ruby_doc/config. Finally, File.expand_path allows us to resolve relative paths, in this case the final result will be /usr/home/foo/dev/ruby_doc/favs.txt.
    This way you don't need to specify any absolute paths or make assumptions about a directory layout, and also ensure that the path exists (as the source file's directory and its parent always exist).