Repository navigation
Conversation
Add test for ToolError handling in structured content.
chrikrah
left a comment
There was a problem hiding this comment.
@jjt998 the fix is right, and the branch still wants ./scripts/format. Nothing here blocks a merge. ./scripts/lint is what CI runs, and it passes.
non-blocking: ruff format wants two hunks in tests/lib/tools/test_session_runner.py. The blank line at :909 carries four trailing spaces, unrelated to the fix. The nested boom helper in the new test wants a blank line either side. [tool.ruff.lint] select omits W, so ruff check stays quiet.
non-blocking: #1837 adds the identical content = list(content) line.
Verification
git archive of 950052d into a clean directory, then uv sync --all-extras. ruff 0.15.6, pyright 1.1.399.
$ sed -n '909p' tests/lib/tools/test_session_runner.py | cat -A
$
$ uv run ruff format --diff tests/lib/tools/test_session_runner.py
--- tests/lib/tools/test_session_runner.py
+++ tests/lib/tools/test_session_runner.py
@@ -906,7 +906,7 @@
# the blank line above the first assert loses its four spaces
@@ -1730,9 +1730,11 @@
# a blank line arrives before `async def boom` and before `tool = _FakeTool`
1 file would be reformatted
$ uv run ruff check .
All checks passed!
$ uv run pyright --project .
186 errors, 16 warnings, 0 informations
# all 186 are in tests/test_middleware.py, which this branch does not touch; the two changed files are clean
$ uv run pytest tests/lib/tools/test_session_runner.py -q -p no:randomly
57 passed in 7.56s
# src/anthropic/lib/tools/_beta_functions.py restored to 4421d56, the test kept
$ uv run pytest tests/lib/tools/test_session_runner.py -q -p no:randomly
1 failed, 56 passed in 7.29s
FAILED tests/lib/tools/test_session_runner.py::test_tool_error_preserves_generator_content
# not run: the rest of tests/, and any run on Windows
CODEOWNERS carries only * @anthropics/sdk. @dtmeadows-ant merged the last two outside changes under src/anthropic/lib (#1795, #1592). @jjt998, will you run ./scripts/format before a maintainer reads this?
Summary
ToolErroraccepts structured content as anIterable. When callers passed a one-shot iterable such as a generator, the constructor consumed it while building the exception message, leaving the runner with empty tool-result content.Materialize non-string content once before deriving the message so the same structured blocks remain available to the tool runner.
Tests
ToolErrorcontent.ruff checkandpy_compilepass locally; the full test suite could not run because the environment is missing the repository'shttpx2development dependency.