Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rubocop: Error - rubocop returned exit code 2

I just cloned a Ruby on Rails project to my local machine to work on it. I have ran the command bundle install in order to install all the necessary gems and dependencies required for the project.

But a message keeps popping up in my log messages, which gets me worried. It is

Error:Rubocop returned exit code: 2

I have checked the version of rubocop that I have installed and it seems to be up-to-date. I have also done some research as to what might be the cause of this error, but I seem not to have any luck yet. I need some assistance.

like image 390
Promise Preston Avatar asked Oct 09 '19 17:10

Promise Preston


1 Answers

According to RuboCop HQ commit message in relation to this issue (Return exit code 2 if RuboCop fails due to internal error), it was stated that "RuboCop returns process exit code 2 if it fails due to bad configuration, bad CLI options, or an internal error. If it runs successfully but finds one or more offenses, it still exits with code 1, as was previously the case. This is helpful when invoking RuboCop programmatically, perhaps from a script."

After a more thorough review of my application, I checked the log message and realized that I was also having an error below the Error:Rubocop returned exit code: 2, which is cannot load such file -- rubocop-performance.

So I quickly checked my Gemfile and realized that some gems listed in my Gemfile that have rubocop as a runtime dependency have not been installed.

The full list of the gems are

gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'

All I had to do was to simply install the gems individually via my terminal

gem install rubocop-performance
gem install rubocop-rails
gem install rubocop-rspec

And that fixed the issue for me.

That's all.

I hope this helps

like image 61
Promise Preston Avatar answered Oct 02 '22 15:10

Promise Preston