Zum Inhalt springen

Log And Rethrow Duplication (ARCH2166)

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

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

Logging an exception and then rethrowing it in the same handler produces duplicate log entries, since it gets logged again higher in the stack. This causes the same error to appear as multiple entries.

def handle(req):
try:
return process(req)
except ValidationError:
logger.exception("Validation error")
raise
def handle(req):
try:
return process(req)
except ValidationError:
raise

Just re-raise the exception; log it at a single layer that owns the responsibility.