Skip to content

Commit

Permalink
Tweak the infinite loop error message
Browse files Browse the repository at this point in the history
This PR tweaks the infinite loop error message.

The single-line, monochromatic error message will be separated into error and hint sections,
with each section color-coded to enhance visibility.
  • Loading branch information
koic authored and bbatsov committed Apr 23, 2024
1 parent abde479 commit 240a0da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
9 changes: 5 additions & 4 deletions lib/rubocop/runner.rb
Expand Up @@ -20,10 +20,11 @@ def initialize(path, offenses_by_iteration, loop_start: -1)
message = 'Infinite loop detected'
message += " in #{path}" if path
message += " and caused by #{root_cause}" if root_cause
message += ' Hint: Please update to the latest RuboCop version if not already in use,'
message += ' and report a bug if the issue still occurs on this version.'
message += ' Please check the latest version at https://rubygems.org/gems/rubocop'
super(message)
message += "\n"
hint = 'Hint: Please update to the latest RuboCop version if not already in use, ' \
"and report a bug if the issue still occurs on this version.\n" \
'Please check the latest version at https://rubygems.org/gems/rubocop.'
super(Rainbow(message).red + Rainbow(hint).yellow)
end
end

Expand Down
25 changes: 12 additions & 13 deletions spec/rubocop/runner_spec.rb
Expand Up @@ -315,10 +315,10 @@ class Klass
end.to raise_error(
described_class::InfiniteCorrectionLoop,
"Infinite loop detected in #{source_file_path} and caused by " \
'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop ' \
"Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop\n" \
'Hint: Please update to the latest RuboCop version if not already in use, ' \
'and report a bug if the issue still occurs on this version. ' \
'Please check the latest version at https://rubygems.org/gems/rubocop'
"and report a bug if the issue still occurs on this version.\n" \
'Please check the latest version at https://rubygems.org/gems/rubocop.'
)
end
end
Expand All @@ -338,10 +338,10 @@ class AnotherKlass
end.to raise_error(
described_class::InfiniteCorrectionLoop,
"Infinite loop detected in #{source_file_path} and caused by " \
'Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop ' \
"Test/ClassMustBeAModuleCop -> Test/ModuleMustBeAClassCop\n" \
'Hint: Please update to the latest RuboCop version if not already in use, ' \
'and report a bug if the issue still occurs on this version. ' \
'Please check the latest version at https://rubygems.org/gems/rubocop'
"and report a bug if the issue still occurs on this version.\n" \
'Please check the latest version at https://rubygems.org/gems/rubocop.'
)
end
end
Expand Down Expand Up @@ -377,11 +377,10 @@ class A_A
end.to raise_error(
described_class::InfiniteCorrectionLoop,
"Infinite loop detected in #{source_file_path} and caused by " \
'Test/ClassMustBeAModuleCop, Test/AtoB ' \
'-> Test/ModuleMustBeAClassCop, Test/BtoA ' \
"Test/ClassMustBeAModuleCop, Test/AtoB -> Test/ModuleMustBeAClassCop, Test/BtoA\n" \
'Hint: Please update to the latest RuboCop version if not already in use, ' \
'and report a bug if the issue still occurs on this version. ' \
'Please check the latest version at https://rubygems.org/gems/rubocop'
"and report a bug if the issue still occurs on this version.\n" \
'Please check the latest version at https://rubygems.org/gems/rubocop.'
)
end
end
Expand Down Expand Up @@ -415,10 +414,10 @@ class A
end.to raise_error(
described_class::InfiniteCorrectionLoop,
"Infinite loop detected in #{source_file_path} and caused by " \
'Test/AtoB -> Test/BtoC -> Test/CtoA ' \
"Test/AtoB -> Test/BtoC -> Test/CtoA\n" \
'Hint: Please update to the latest RuboCop version if not already in use, ' \
'and report a bug if the issue still occurs on this version. ' \
'Please check the latest version at https://rubygems.org/gems/rubocop'
"and report a bug if the issue still occurs on this version.\n" \
'Please check the latest version at https://rubygems.org/gems/rubocop.'
)
end
end
Expand Down

0 comments on commit 240a0da

Please sign in to comment.