mirror of
https://github.com/ZhuLinsen/daily_stock_analysis
synced 2026-09-20 02:43:35 +08:00
fix(issue-968): [bug]-bot-ask-命令技能加载失败时异常被静默吞掉,故障无日志可查 (#972)
This commit is contained in:
@@ -128,7 +128,8 @@ class AskCommand(BotCommand):
|
||||
|
||||
sm = get_skill_manager()
|
||||
return list(sm.list_skills())
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning("_load_skills failed: %s", e, exc_info=True)
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
@@ -137,7 +138,8 @@ class AskCommand(BotCommand):
|
||||
from src.agent.skills.defaults import get_primary_default_skill_id
|
||||
|
||||
return get_primary_default_skill_id(cls._load_skills())
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
logger.warning("_get_default_skill_id failed: %s", e, exc_info=True)
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -344,5 +344,26 @@ class TestAskCommandMultiStock(unittest.TestCase):
|
||||
self.assertEqual(captured["context"]["strategies"], ["chan_theory"])
|
||||
|
||||
|
||||
class TestAskCommandSilentExceptionFix(unittest.TestCase):
|
||||
"""Verify that _load_skills and _get_default_skill_id log warnings on failure."""
|
||||
|
||||
def test_load_skills_logs_warning_and_returns_empty_list(self):
|
||||
boom = RuntimeError("skill manager unavailable")
|
||||
with patch("src.agent.factory.get_skill_manager", side_effect=boom):
|
||||
with self.assertLogs("bot.commands.ask", level="WARNING") as cm:
|
||||
result = AskCommand._load_skills()
|
||||
self.assertEqual(result, [])
|
||||
self.assertTrue(any("_load_skills failed" in line for line in cm.output))
|
||||
|
||||
def test_get_default_skill_id_logs_warning_and_returns_empty_string(self):
|
||||
boom = RuntimeError("defaults unavailable")
|
||||
with patch.object(AskCommand, "_load_skills", return_value=[]):
|
||||
with patch("src.agent.skills.defaults.get_primary_default_skill_id", side_effect=boom):
|
||||
with self.assertLogs("bot.commands.ask", level="WARNING") as cm:
|
||||
result = AskCommand._get_default_skill_id()
|
||||
self.assertEqual(result, "")
|
||||
self.assertTrue(any("_get_default_skill_id failed" in line for line in cm.output))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user