Skip to content

Commit a1f2863

Browse files
committed
test: add coverage for generic exception handler in call_tool
The lowlevel server's call_tool decorator has both a ToolError handler and a generic Exception handler. This test ensures the generic Exception path is covered for 100% code coverage.
1 parent 43ee418 commit a1f2863

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/issues/test_348_tool_error_content.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,24 @@ def fail_simple() -> str:
197197
assert len(result.content) == 1
198198
assert isinstance(result.content[0], TextContent)
199199
assert "Simple error message" in result.content[0].text
200+
201+
202+
async def test_generic_exception_returns_error():
203+
"""Test that a generic Exception (not ToolError) returns isError=True."""
204+
server = Server("test")
205+
206+
@server.list_tools()
207+
async def list_tools():
208+
return [create_tool("fail", "Raises generic exception")]
209+
210+
@server.call_tool()
211+
async def call_tool(name: str, arguments: dict[str, Any]):
212+
raise ValueError("A generic error occurred")
213+
214+
async with client_session(server) as client:
215+
result = await client.call_tool("fail", {})
216+
217+
assert result.isError is True
218+
assert len(result.content) == 1
219+
assert isinstance(result.content[0], TextContent)
220+
assert "A generic error occurred" in result.content[0].text

0 commit comments

Comments
 (0)