Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: code Interpreter error handling not work (#21736)

quicksand4198a533ade7
diff --git a/api/core/tools/builtin_tool/providers/code/tools/simple_code.py b/api/core/tools/builtin_tool/providers/code/tools/simple_code.py
index ab0e155b981..b4e650e0edc 100644
--- a/api/core/tools/builtin_tool/providers/code/tools/simple_code.py
+++ b/api/core/tools/builtin_tool/providers/code/tools/simple_code.py
@@ -4,6 +4,7 @@ from typing import Any, Optional
from core.helper.code_executor.code_executor import CodeExecutor, CodeLanguage
from core.tools.builtin_tool.tool import BuiltinTool
from core.tools.entities.tool_entities import ToolInvokeMessage
+from core.tools.errors import ToolInvokeError
class SimpleCode(BuiltinTool):
@@ -25,6 +26,8 @@ class SimpleCode(BuiltinTool):
if language not in {CodeLanguage.PYTHON3, CodeLanguage.JAVASCRIPT}:
raise ValueError(f"Only python3 and javascript are supported, not {language}")
- result = CodeExecutor.execute_code(language, "", code)
-
- yield self.create_text_message(result)
+ try:
+ result = CodeExecutor.execute_code(language, "", code)
+ yield self.create_text_message(result)
+ except Exception as e:
+ raise ToolInvokeError(str(e))