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

Style/RaiseArgs cop gets error when raised class is in a variable #10589

Closed
gongfarmer opened this issue Apr 28, 2022 · 0 comments · Fixed by #10590
Closed

Style/RaiseArgs cop gets error when raised class is in a variable #10589

gongfarmer opened this issue Apr 28, 2022 · 0 comments · Fixed by #10590
Labels

Comments

@gongfarmer
Copy link

Code being checked

$ ruby -c sample.rb
Syntax OK

$ cat sample.rb
# frozen_string_literal: true

# Raise error if a shell command has failed to pack/unpack repository.
def handle_exit_status(status, err_class, err_msg, path, output)
  return if status.success?

  msg =
    if output.include?('Bad session key')
      "#{err_msg} #{path}, incorrect passphrase"
    else
      "#{err_msg} #{path}: #{output}"
    end
  raise(err_class, msg)
end

Expected output

Expected output: no error

Actual output:


$ rubocop sample.rb
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
To see the complete backtrace run rubocop -d.
Inspecting 1 file
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
To see the complete backtrace run rubocop -d.
C

Offenses:

sample.rb:7:3: C: [Correctable] Style/ConditionalAssignment: Assign variables inside of conditionals
  msg = ...
  ^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable

1 error occurred:
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.28.2 (using Parser 3.1.1.0, rubocop-ast 1.17.0, running on ruby 2.7.4 x86_64-linux-gnu)

This is caused by my rubocop configuration.

Running rubocop with no configuration does not trigger the error:

$ rubocop -c /dev/null sample.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Rubocop version

$ rubocop -V
1.28.2 (using Parser 3.1.1.0, rubocop-ast 1.17.0, running on ruby 2.7.4 x86_64-linux-gnu)

Rubocop debug output

$ cat .rubocop.yml 
Style/RaiseArgs:
  EnforcedStyle: compact


$ rubocop --debug sample.rb 
For /data/home/fhanson/git/storagegrid/gpt2/src: configuration from /data/home/fhanson/git/storagegrid/gpt2/src/.rubocop.yml
Default configuration from /var/lib/gems/2.7.0/gems/rubocop-1.28.2/config/default.yml
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.

Please also note that you can opt-in to new cops by default by adding this to your config:
  AllCops:
    NewCops: enable

Gemspec/DateAssignment: # new in 1.10
  Enabled: true
Gemspec/RequireMFA: # new in 1.23
  Enabled: true
Layout/LineEndStringConcatenationIndentation: # new in 1.18
  Enabled: true
Layout/SpaceBeforeBrackets: # new in 1.7
  Enabled: true
Lint/AmbiguousAssignment: # new in 1.7
  Enabled: true
Lint/AmbiguousOperatorPrecedence: # new in 1.21
  Enabled: true
Lint/AmbiguousRange: # new in 1.19
  Enabled: true
Lint/DeprecatedConstants: # new in 1.8
  Enabled: true
Lint/DuplicateBranch: # new in 1.3
  Enabled: true
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
  Enabled: true
Lint/EmptyBlock: # new in 1.1
  Enabled: true
Lint/EmptyClass: # new in 1.3
  Enabled: true
Lint/EmptyInPattern: # new in 1.16
  Enabled: true
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
  Enabled: true
Lint/LambdaWithoutLiteralBlock: # new in 1.8
  Enabled: true
Lint/NoReturnInBeginEndBlocks: # new in 1.2
  Enabled: true
Lint/NumberedParameterAssignment: # new in 1.9
  Enabled: true
Lint/OrAssignmentToConstant: # new in 1.9
  Enabled: true
Lint/RedundantDirGlobSort: # new in 1.8
  Enabled: true
Lint/RefinementImportMethods: # new in 1.27
  Enabled: true
Lint/RequireRelativeSelfPath: # new in 1.22
  Enabled: true
Lint/SymbolConversion: # new in 1.9
  Enabled: true
Lint/ToEnumArguments: # new in 1.1
  Enabled: true
Lint/TripleQuotes: # new in 1.9
  Enabled: true
Lint/UnexpectedBlockArity: # new in 1.5
  Enabled: true
Lint/UnmodifiedReduceAccumulator: # new in 1.1
  Enabled: true
Lint/UselessRuby2Keywords: # new in 1.23
  Enabled: true
Naming/BlockForwarding: # new in 1.24
  Enabled: true
Security/CompoundHash: # new in 1.28
  Enabled: true
Security/IoMethods: # new in 1.22
  Enabled: true
Style/ArgumentsForwarding: # new in 1.1
  Enabled: true
Style/CollectionCompact: # new in 1.2
  Enabled: true
Style/DocumentDynamicEvalDefinition: # new in 1.1
  Enabled: true
Style/EndlessMethod: # new in 1.8
  Enabled: true
Style/FetchEnvVar: # new in 1.28
  Enabled: true
Style/FileRead: # new in 1.24
  Enabled: true
Style/FileWrite: # new in 1.24
  Enabled: true
Style/HashConversion: # new in 1.10
  Enabled: true
Style/HashExcept: # new in 1.7
  Enabled: true
Style/IfWithBooleanLiteralBranches: # new in 1.9
  Enabled: true
Style/InPatternThen: # new in 1.16
  Enabled: true
Style/MapToHash: # new in 1.24
  Enabled: true
Style/MultilineInPatternThen: # new in 1.16
  Enabled: true
Style/NegatedIfElseCondition: # new in 1.2
  Enabled: true
Style/NestedFileDirname: # new in 1.26
  Enabled: true
Style/NilLambda: # new in 1.3
  Enabled: true
Style/NumberedParameters: # new in 1.22
  Enabled: true
Style/NumberedParametersLimit: # new in 1.22
  Enabled: true
Style/ObjectThen: # new in 1.28
  Enabled: true
Style/OpenStructUse: # new in 1.23
  Enabled: true
Style/QuotedSymbols: # new in 1.16
  Enabled: true
Style/RedundantArgument: # new in 1.4
  Enabled: true
Style/RedundantInitialize: # new in 1.27
  Enabled: true
Style/RedundantSelfAssignmentBranch: # new in 1.19
  Enabled: true
Style/SelectByRegexp: # new in 1.22
  Enabled: true
Style/StringChars: # new in 1.12
  Enabled: true
Style/SwapValues: # new in 1.1
  Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html
Use parallel by default.
Running parallel inspection
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
undefined method `source' for nil:NilClass
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:83:in `correction_exploded_to_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:95:in `block in check_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/base.rb:342:in `correct'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/base.rb:127:in `add_offense'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:94:in `check_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:58:in `on_send'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:134:in `each'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `each'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:153:in `on_def'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/team.rb:83:in `investigate'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:307:in `inspect_file'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:251:in `block in do_inspection_loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:285:in `block in iterate_until_no_changes'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `iterate_until_no_changes'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:247:in `do_inspection_loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:130:in `block in file_offenses'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:155:in `file_offense_cache'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:129:in `file_offenses'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:67:in `block in warm_cache'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:515:in `call_with_index'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:485:in `process_incoming_jobs'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:465:in `block in worker'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `fork'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `worker'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:447:in `block in create_workers'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each_with_index'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `create_workers'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:386:in `work_in_processes'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:289:in `map'
/var/lib/gems/2.7.0/gems/parallel-1.21.0/lib/parallel.rb:238:in `each'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:67:in `warm_cache'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:46:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command.rb:11:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/environment.rb:18:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:71:in `run_command'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:78:in `execute_runners'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:47:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/exe/rubocop:12:in `block in <top (required)>'
/var/lib/gems/2.7.0/gems/benchmark-0.2.0/lib/benchmark.rb:311:in `realtime'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/exe/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'
Inspecting 1 file
Scanning /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
undefined method `source' for nil:NilClass
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:83:in `correction_exploded_to_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:95:in `block in check_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/base.rb:342:in `correct'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/base.rb:127:in `add_offense'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:94:in `check_compact'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/style/raise_args.rb:58:in `on_send'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:134:in `each'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `block in on_dstr'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `each'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:136:in `on_dstr'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:153:in `on_def'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/var/lib/gems/2.7.0/gems/rubocop-ast-1.17.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cop/team.rb:83:in `investigate'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:307:in `inspect_file'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:251:in `block in do_inspection_loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:285:in `block in iterate_until_no_changes'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:278:in `iterate_until_no_changes'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:247:in `do_inspection_loop'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:130:in `block in file_offenses'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:155:in `file_offense_cache'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:129:in `file_offenses'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:120:in `process_file'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `each'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `reduce'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:100:in `each_inspected_file'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:86:in `inspect_files'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/runner.rb:47:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/command.rb:11:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli/environment.rb:18:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:71:in `run_command'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:78:in `execute_runners'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/lib/rubocop/cli.rb:47:in `run'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/exe/rubocop:12:in `block in <top (required)>'
/var/lib/gems/2.7.0/gems/benchmark-0.2.0/lib/benchmark.rb:311:in `realtime'
/var/lib/gems/2.7.0/gems/rubocop-1.28.2/exe/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:23:in `load'
/usr/local/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Style/RaiseArgs cop was inspecting /data/home/fhanson/git/storagegrid/gpt2/src/sample.rb:13:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.28.2 (using Parser 3.1.1.0, rubocop-ast 1.17.0, running on ruby 2.7.4 x86_64-linux-gnu)
Finished in 0.36043624207377434 seconds

@koic koic added the bug label Apr 29, 2022
nobuyo added a commit to nobuyo/rubocop that referenced this issue Apr 29, 2022
…cedStyle: compact` and exception object is assigned to a local variable.

Update lib/rubocop/cop/style/raise_args.rb

Co-authored-by: Koichi ITO <koic.ito@gmail.com>
koic added a commit that referenced this issue Apr 29, 2022
…-args-with-compact-style

[Fix #10589] Fix autocorrect for `Style/RaiseArgs` with `EnforcedStyle: compact`
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