Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(channels): repair broken log format strings that crash on a failed channel load

Lanre Shittu73534ee25a32
diff --git a/agent/src/channels/registry.py b/agent/src/channels/registry.py
index b261ee290..30af3900e 100644
--- a/agent/src/channels/registry.py
+++ b/agent/src/channels/registry.py
@@ -261,9 +261,9 @@ def discover_plugins(
try:
cls = ep.load()
plugins[ep.name] = cls
- except Exception:
+ except Exception as exc:
logger.warning(
- "Failed to load channel plugin '%s': %s", ep.name, exc_info=True
+ "Failed to load channel plugin '%s': %s", ep.name, exc, exc_info=True
)
return plugins
@@ -287,8 +287,10 @@ def discover_enabled(
continue
try:
result[modname] = load_channel_class(modname)
- except ImportError:
- logger.debug("Skipping built-in channel '%s': %s", modname, exc_info=True)
+ except ImportError as exc:
+ logger.debug(
+ "Skipping built-in channel '%s': %s", modname, exc, exc_info=True
+ )
external = discover_plugins(None if _include_all_external else enabled_names)
shadowed = set(external) & set(result)
diff --git a/agent/tests/test_channel_registry_logging.py b/agent/tests/test_channel_registry_logging.py
new file mode 100644
index 000000000..7bddb89c7
--- /dev/null
+++ b/agent/tests/test_channel_registry_logging.py
@@ -0,0 +1,59 @@
+"""A failed channel load must produce a readable log, not a logging crash.
+
+``logger.warning("... '%s': %s", name, exc_info=True)`` supplies only one
+positional argument for two ``%s`` placeholders. ``logging`` formats lazily,
+so this doesn't raise where it's called -- it raises inside the handler's
+``emit()``, which swallows it and prints "--- Logging error ---" instead of
+the message. The diagnostic the operator needed (which plugin, and why) never
+reaches the log.
+"""
+
+from __future__ import annotations
+
+import importlib.metadata
+from typing import Any
+
+from src.channels import registry
+
+
+class _FailingEntryPoint:
+ name = "broken_plugin"
+
+ def load(self) -> Any:
+ raise RuntimeError("boom")
+
+
+def test_discover_plugins_logs_the_failure_reason_without_crashing(monkeypatch, caplog):
+ monkeypatch.setattr(
+ importlib.metadata,
+ "entry_points",
+ lambda group=None: (
+ [_FailingEntryPoint()] if group == "vibe_trading.channels" else []
+ ),
+ )
+
+ with caplog.at_level("WARNING", logger="src.channels.registry"):
+ plugins = registry.discover_plugins()
+
+ assert plugins == {}
+ messages = [record.getMessage() for record in caplog.records]
+ assert any("broken_plugin" in m and "boom" in m for m in messages), messages
+
+
+def test_discover_enabled_logs_the_skip_reason_without_crashing(monkeypatch, caplog):
+ def _boom(module_name: str) -> Any:
+ raise ImportError("missing optional sdk")
+
+ monkeypatch.setattr(registry, "load_channel_class", _boom)
+ monkeypatch.setattr(registry, "discover_plugins", lambda *a, **k: {})
+
+ with caplog.at_level("DEBUG", logger="src.channels.registry"):
+ result = registry.discover_enabled(
+ {"broken_channel"}, _names=["broken_channel"]
+ )
+
+ assert result == {}
+ messages = [record.getMessage() for record in caplog.records]
+ assert any(
+ "broken_channel" in m and "missing optional sdk" in m for m in messages
+ ), messages