Ir al contenido

Catch Without Log Or Rethrow (ARCH6165)

Esta página aún no está disponible en tu idioma.

Key ruby.logging.catch-log-only · Severity info · Category logging

A handler that catches and logs an exception, then continues normally without rethrowing, may unintentionally swallow an unrecoverable error. Flow can proceed with corrupt state.

def charge(order)
gateway.charge(order)
rescue PaymentError => e
Rails.logger.error("Payment failed", exception: e)
end
def charge(order)
gateway.charge(order)
rescue PaymentError => e
Rails.logger.error("Payment failed", exception: e)
raise
end

If you cannot truly recover from the error, rethrow after logging instead of logging and continuing.