fix(logging): replace stdlib-style exc_info kwargs with loguru opt(exception=)
Loguru has no exc_info kwarg: extra kwargs are str.format() arguments, so
logger.error(f"...{e}", exc_info=True) forces .format() on the rendered
message — any error text containing braces (e.g. a JSON error body) raises
KeyError FROM the log call itself, escaping the surrounding except block and
killing the caller (observed: whole agent turns dying in benchmark runs).
The intended traceback was also never logged, since exc_info is not a loguru
feature.
Batch fix of all 143 sites across 11 files:
logger.X(msg, exc_info=True) -> logger.opt(exception=True).X(msg)
(one exc_info=exc site -> opt(exception=exc))
Messages are byte-identical; with the kwarg gone loguru never calls
.format(), so brace-containing f-string messages are inert.
Verified: AST post-conditions per file, py_compile, import smoke of all
modules, behavioral equivalence of the 3 patterns, full unit suite (1549
passed) with a failure set identical to the pristine tree (22 pre-existing,
zero regressions).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Also add pixel-agents to the README acknowledgements.
This commit is contained in:
@@ -157,7 +157,16 @@ class ToolRegistry:
|
||||
result = await tool.func(**call_args)
|
||||
output = {"result": result, "success": True}
|
||||
except Exception as e:
|
||||
logger.error(f"Tool {name} failed ({type(e).__name__}): {e}", exc_info=True)
|
||||
# Loguru has no stdlib-style ``exc_info`` kwarg: extra kwargs are
|
||||
# format() arguments, which forces str.format() on the message — an
|
||||
# error message containing ``{...}`` (e.g. a JSON error body) then
|
||||
# raises KeyError FROM the logging call, escaping this handler and
|
||||
# killing the caller instead of returning the error output below.
|
||||
# Positional formatting keeps brace-containing values inert, and
|
||||
# opt(exception=True) is the loguru way to log the traceback.
|
||||
logger.opt(exception=True).error(
|
||||
"Tool {} failed ({}): {}", name, type(e).__name__, e
|
||||
)
|
||||
output = {
|
||||
"error": str(e),
|
||||
"traceback": traceback.format_exc(),
|
||||
|
||||
Reference in New Issue
Block a user