Aller au contenu

Rethrow Loses Stack Trace (ARCH2154)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.logging.raise-without-from · Severity info · Category logging

Calling raise NewError() inside a handler without from e drops the original exception’s stack trace and cause. This hides the true source of the error and makes debugging harder.

try:
config = json.loads(raw)
except ValueError:
raise ConfigError("Invalid configuration")
try:
config = json.loads(raw)
except ValueError as e:
raise ConfigError("Invalid configuration") from e

Raise the new exception with raise ... from e to preserve the original cause and stack trace.