From 17776b42bf56c0cf601cab1b94630b25fe2ab3fa Mon Sep 17 00:00:00 2001 From: mumu <42829555+ZhuLinsen@users.noreply.github.com> Date: Fri, 3 Apr 2026 13:15:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(issue-968):=20[bug]-bot-ask-=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=8A=80=E8=83=BD=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E6=97=B6=E5=BC=82=E5=B8=B8=E8=A2=AB=E9=9D=99=E9=BB=98=E5=90=9E?= =?UTF-8?q?=E6=8E=89=EF=BC=8C=E6=95=85=E9=9A=9C=E6=97=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=8F=AF=E6=9F=A5=20(#972)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/commands/ask.py | 6 ++++-- tests/test_ask_command.py | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bot/commands/ask.py b/bot/commands/ask.py index b1b3e4f57..8e0dd6405 100644 --- a/bot/commands/ask.py +++ b/bot/commands/ask.py @@ -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 diff --git a/tests/test_ask_command.py b/tests/test_ask_command.py index 4004009e3..165655b0d 100644 --- a/tests/test_ask_command.py +++ b/tests/test_ask_command.py @@ -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()