fix: use proper exception chaining with 'raise from' in glogging.py

Use 'raise X from e' syntax instead of just 'raise X' when wrapping
exceptions. This provides more accurate exception chaining messages
("The above exception was the direct cause of" vs "During handling of").

Closes #2360
This commit is contained in:
Benoit Chesneau 2026-01-23 10:59:05 +01:00
parent 33e5337395
commit a182066bea

View File

@ -237,7 +237,7 @@ class Logger:
ValueError,
TypeError
) as exc:
raise RuntimeError(str(exc))
raise RuntimeError(str(exc)) from exc
elif cfg.logconfig_json:
config = CONFIG_DEFAULTS.copy()
if os.path.exists(cfg.logconfig_json):
@ -252,7 +252,7 @@ class Logger:
ValueError,
TypeError
) as exc:
raise RuntimeError(str(exc))
raise RuntimeError(str(exc)) from exc
elif cfg.logconfig:
if os.path.exists(cfg.logconfig):
defaults = CONFIG_DEFAULTS.copy()
@ -442,8 +442,8 @@ class Logger:
# syslog facility
try:
facility = SYSLOG_FACILITIES[cfg.syslog_facility.lower()]
except KeyError:
raise RuntimeError("unknown facility name")
except KeyError as exc:
raise RuntimeError("unknown facility name") from exc
# parse syslog address
socktype, addr = parse_syslog_address(cfg.syslog_addr)