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 Style/RedundantFetchBlock cop was inspecting file #8195

Closed
acallaghan opened this issue Jun 23, 2020 · 3 comments · Fixed by #8197
Closed

An error occurred while Style/RedundantFetchBlock cop was inspecting file #8195

acallaghan opened this issue Jun 23, 2020 · 3 comments · Fixed by #8197
Labels

Comments

@acallaghan
Copy link

Hi there,

I've experienced this bug with the Style/RedundantFetchBlock cop today, and it suggested to make a bug report, so here I am.


Expected behavior

Rubocop doesn't throw exception

Actual behavior

1 error occurred:
An error occurred while Style/RedundantFetchBlock cop was inspecting -file-
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.0.3, running on ruby 2.6.4 x86_64-darwin19)
Finished in 1.0352169999969192 seconds

Steps to reproduce the problem

be rubocop -d file

I can't disclose the source file here, but I can try and whittle down a failing case from it if you need it

Backtrace

An error occurred while Style/RedundantFetchBlock cop was inspecting {{file}}
undefined method `basic_literal?' for nil:NilClass
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/style/redundant_fetch_block.rb:76:in `basic_literal?'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/style/redundant_fetch_block.rb:52:in `redundant_fetch_block_candidate?'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/style/redundant_fetch_block.rb:48:in `on_block'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:56:in `block (2 levels) in trigger_responding_cops'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:115:in `with_cop_error_handling'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:55:in `block in trigger_responding_cops'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:54:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:54:in `trigger_responding_cops'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:32:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:114:in `block in on_send'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:111:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:111:in `each_with_index'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:111:in `on_send'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `block in on_begin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `on_begin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:171:in `on_block'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `block in on_kwbegin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `on_kwbegin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `block in on_or_asgn'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `on_or_asgn'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:107:in `on_def'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `block in on_begin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:57:in `on_begin'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:99:in `on_class'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:157:in `on_while'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-ast-0.0.3/lib/rubocop/ast/traversal.rb:14:in `walk'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/commissioner.rb:43:in `investigate'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/team.rb:149:in `investigate'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/team.rb:137:in `offenses'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cop/team.rb:75:in `inspect_file'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:299:in `inspect_file'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:247:in `block in do_inspection_loop'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:279:in `block in iterate_until_no_changes'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:272:in `loop'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:272:in `iterate_until_no_changes'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:243:in `do_inspection_loop'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:122:in `block in file_offenses'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:146:in `file_offense_cache'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:120:in `file_offenses'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:111:in `process_file'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:90:in `block in each_inspected_file'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:89:in `each'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:89:in `reduce'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:89:in `each_inspected_file'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:78:in `inspect_files'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/runner.rb:39:in `run'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli/command.rb:10:in `run'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli/environment.rb:17:in `run'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli.rb:65:in `run_command'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli.rb:72:in `execute_runners'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/lib/rubocop/cli.rb:41:in `run'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/exe/rubocop:13:in `block in <top (required)>'
~/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.86.0/exe/rubocop:12:in `<top (required)>'
~/.rbenv/versions/2.6.4/bin/rubocop:23:in `load'
~/.rbenv/versions/2.6.4/bin/rubocop:23:in `<top (required)>'

I've redacted parts that weren't relevant

RuboCop version

``
$ bundle exec rubocop -V
0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.0.3, running on ruby 2.6.4 x86_64-darwin19)

@koic
Copy link
Member

koic commented Jun 23, 2020

I can't disclose the source file here, but I can try and whittle down a failing case from it if you need it

Yeah, the minimal reproducible code that happens the error will be a clue to the issue.

@acallaghan
Copy link
Author

@koic So i've whittled it down, this generates no rubocop offenses, but triggers the error:

class Master
  def method
    b.fetch(c) {}
  end
end

@koic koic added the bug label Jun 23, 2020
koic added a commit to koic/rubocop that referenced this issue Jun 23, 2020
Fixes rubocop#8195

This PR fixes an error for `Style/RedundantFetchBlock` when using
`#fetch` with empty block.
@koic
Copy link
Member

koic commented Jun 23, 2020

@acallaghan Thanks for showing the reproduction code. I opened PR #8197.

bbatsov pushed a commit that referenced this issue Jun 23, 2020
Fixes #8195

This PR fixes an error for `Style/RedundantFetchBlock` when using
`#fetch` with empty block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants