Class: RuboCop::Cop::Legion::RescueLogging::NoCapture
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::RescueLogging::NoCapture
- Defined in:
- lib/rubocop/cop/legion/rescue_logging/no_capture.rb
Overview
Detects ‘rescue SomeError` where the exception class is specified but no `=> e` capture is present, and auto-corrects by appending `=> e`.
Constant Summary collapse
- MSG =
'Exception class specified but not captured. ' \ 'Use `rescue %<classes>s => e` and log the exception.'
Instance Method Summary collapse
Instance Method Details
#on_resbody(node) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rubocop/cop/legion/rescue_logging/no_capture.rb', line 29 def on_resbody(node) return if node.exceptions.empty? || !node.exception_variable.nil? return if rescue_modifier?(node) classes = node.exceptions.map(&:source).join(', ') = format(MSG, classes: classes) add_offense(node, message: , severity: :convention) end |