Zum Inhalt springen

Log And Rethrow Duplication (ARCH6166)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key ruby.logging.log-and-rethrow · Severity warning · Category logging

Logging an exception and then rethrowing it in the same handler produces duplicate log entries when it is logged again higher in the stack. The same error gets reported multiple times.

def import(file)
parse(file)
rescue ParseError => e
Rails.logger.error("Import failed", exception: e)
raise
end
def import(file)
parse(file)
rescue ParseError
raise
end

Either log and swallow the exception here, or rethrow without logging and log once at the top boundary.