Class: RuboCop::Cop::Legion::Llm::RescueLogLevel

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/legion/llm/rescue_log_level.rb

Overview

Flags ‘handle_exception(e, level: :debug)` in rescue blocks. Exception handlers must use at least `:warn` so that errors are visible in production logs without enabling debug mode.

Examples:

# bad
rescue StandardError => e
  handle_exception(e, level: :debug, operation: 'foo')
end

# good
rescue StandardError => e
  handle_exception(e, level: :warn, operation: 'foo')
end

Constant Summary collapse

MSG =
'`handle_exception` called with `level: :debug` in a rescue. ' \
'Minimum log level for exceptions is `:warn`.'
DEBUG_LEVELS =
%i[debug trace verbose].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/rubocop/cop/legion/llm/rescue_log_level.rb', line 27

def on_send(node)
  return unless node.method_name == :handle_exception
  return unless inside_rescue?(node)
  return unless debug_level?(node)

  add_offense(node)
end