Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

fix(dspy): root CodeInterpreterError under DSPyError (#10134)

Isaac Miller8ca62a490f81
diff --git a/dspy/primitives/code_interpreter.py b/dspy/primitives/code_interpreter.py
index 6e44a19eb..8a0393ebf 100644
--- a/dspy/primitives/code_interpreter.py
+++ b/dspy/primitives/code_interpreter.py
@@ -9,11 +9,13 @@ code-executing modules to work with different interpreter implementations:
from typing import Any, Callable, Protocol, runtime_checkable
+from dspy.utils.exceptions import DSPyError
+
# Types that can be used directly in Python function signatures for SUBMIT()
SIMPLE_TYPES = (str, int, float, bool, list, dict, type(None))
-class CodeInterpreterError(RuntimeError):
+class CodeInterpreterError(DSPyError, RuntimeError):
"""Base class for errors reported by a code interpreter.
A bare instance indicates a failure that submitted code cannot repair, such
diff --git a/tests/primitives/test_code_interpreter.py b/tests/primitives/test_code_interpreter.py
new file mode 100644
index 000000000..f9de9cbf8
--- /dev/null
+++ b/tests/primitives/test_code_interpreter.py
@@ -0,0 +1,21 @@
+import dspy
+from dspy.primitives.code_interpreter import CodeExecutionError, CodeInterpreterError
+
+
+def test_code_interpreter_error_is_dspy_error():
+ error = CodeInterpreterError("boom")
+ assert isinstance(error, dspy.DSPyError)
+ assert isinstance(error, RuntimeError)
+ assert str(error) == "boom"
+ assert error.args == ("boom",)
+
+ try:
+ raise error
+ except RuntimeError as caught:
+ assert caught is error
+
+
+def test_code_execution_error_is_dspy_error():
+ error = CodeExecutionError("boom")
+ assert isinstance(error, dspy.DSPyError)
+ assert isinstance(error, CodeInterpreterError)