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

"An error occurred while Rails/UnknownEnv cop was inspecting" files in version 2.22.1 #1172

Closed
lavaturtle opened this issue Oct 30, 2023 · 3 comments · Fixed by #1175
Closed
Labels
bug Something isn't working

Comments

@lavaturtle
Copy link

I'm trying to upgrade rubocop-rails from version 2.21.2 to version 2.22.1. Rubocop runs fine with the older version. On the newer version, I see a bunch of errors like this:

An error occurred while Rails/UnknownEnv cop was inspecting /srv/agra/spec/models/email_spec.rb:75:38.


Expected behavior

I expected RuboCop Rails not to generate errors while running.

Actual behavior

When I run rubocop, I see a bunch of errors like An error occurred while Rails/UnknownEnv cop was inspecting (some file name and line number).

When I run with -d, I see this backtrace for the error:

no implicit conversion of Array into String
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-rails-2.22.1/lib/rubocop/cop/rails/unknown_env.rb:91:in `+'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-rails-2.22.1/lib/rubocop/cop/rails/unknown_env.rb:91:in `environments'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-rails-2.22.1/lib/rubocop/cop/rails/unknown_env.rb:85:in `unknown_env_name?'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-rails-2.22.1/lib/rubocop/cop/rails/unknown_env.rb:47:in `unknown_environment_equal?'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-rails-2.22.1/lib/rubocop/cop/rails/unknown_env.rb:46:in `on_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:105:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:69:in `on_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:156:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:156:in `on_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:155:in `on_if'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_if'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:154:in `on_def'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:154:in `on_class'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cop/team.rb:98:in `investigate'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:345:in `block in inspect_file'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:344:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:344:in `flat_map'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:344:in `inspect_file'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:314:in `loop'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:164:in `block in file_offenses'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:189:in `file_offense_cache'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:163:in `file_offenses'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:154:in `process_file'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:134:in `each'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:134:in `reduce'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:134:in `each_inspected_file'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:120:in `inspect_files'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/runner.rb:73:in `run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/command.rb:11:in `run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli/environment.rb:18:in `run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli.rb:118:in `run_command'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli.rb:125:in `execute_runners'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli.rb:51:in `block in run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli.rb:77:in `profile_if_needed'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/lib/rubocop/cli.rb:43:in `run'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/exe/rubocop:19:in `block in <top (required)>'
/usr/share/rvm/rubies/ruby-3.2.2/lib/ruby/3.2.0/benchmark.rb:311:in `realtime'
/home/grey/.rvm/gems/ruby-3.2.2@agra/gems/rubocop-1.56.3/exe/rubocop:19:in `<top (required)>'
/home/grey/.rvm/gems/ruby-3.2.2@agra/bin/rubocop:25:in `load'
/home/grey/.rvm/gems/ruby-3.2.2@agra/bin/rubocop:25:in `<main>'
/home/grey/.rvm/gems/ruby-3.2.2@agra/bin/ruby_executable_hooks:22:in `eval'
/home/grey/.rvm/gems/ruby-3.2.2@agra/bin/ruby_executable_hooks:22:in `<main>'

Steps to reproduce the problem

  1. Upgrade rubocop-rails to 2.22.1
  2. Run rubocop
  3. Inspect the output

RuboCop version

1.56.3 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-linux]
  - rubocop-performance 1.19.1
  - rubocop-rails 2.22.1
  - rubocop-rspec 2.23.2
@lavaturtle
Copy link
Author

The problem still exists after upgrading RuboCop to the latest version:

1.57.2 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-linux]
  - rubocop-performance 1.19.1
  - rubocop-rails 2.22.1
  - rubocop-rspec 2.25.0

@irphilli
Copy link

I'm getting the same error, but only on a branch where I've upgraded Rails to 7.1.

@lavaturtle
Copy link
Author

I'm also on Rails 7.1, FWIW

@koic koic added the bug Something isn't working label Oct 31, 2023
koic added a commit to koic/rubocop-rails that referenced this issue Oct 31, 2023
Fixes rubocop#1172.

This PR fixes an error for `Rails/UnknownEnv`
when using Rails 7.1.
@koic koic closed this as completed in #1175 Nov 1, 2023
koic added a commit that referenced this issue Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants