Skip to content

Swallowed Exception (ARCH6151)

Key ruby.logging.swallowed-exception · Severity error · Category logging

The handler catches an exception and silently discards it (rescue nil, returning false), hiding the failure. Unlike an empty block there is a body, but it does not process the exception.

def fetch_user(id)
User.find(id)
rescue
nil
end
def fetch_user(id)
User.find(id)
rescue ActiveRecord::RecordNotFound => e
Rails.logger.warn("User not found: #{id}", exception: e)
nil
end

Log the exception structurally and rescue only the expected exception type.