Skip to content

Commit af21cac

Browse files
committed
fix: handle JSONDecodeError in search, simplify local_search serialization
- Add json.JSONDecodeError to _do_search exception handling so malformed registry responses return an error dict instead of crashing - Replace model_dump_json + json.loads with model_dump in _local_search to avoid unnecessary serialize-then-deserialize roundtrip - Remove unnecessary `as _` in test patch context managers - Fix 80-char line limit violation in test docstring
1 parent 4231e92 commit af21cac

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/google/adk_community/tools/ardhf/ardhf_toolset.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,8 @@ def _local_search(
161161
pageSize=limit,
162162
)
163163
response = search_agent_finder(request, token=token)
164-
return json.loads(
165-
response.model_dump_json(
166-
exclude_none=True, exclude_defaults=True
167-
)
164+
return response.model_dump(
165+
exclude_none=True, exclude_defaults=True
168166
)
169167

170168

@@ -285,7 +283,7 @@ async def _do_search(
285283
limit=limit,
286284
token=self._token,
287285
)
288-
except (HTTPError, URLError, TimeoutError) as exc:
286+
except (HTTPError, URLError, TimeoutError, json.JSONDecodeError) as exc:
289287
logger.warning("ARD search failed: %s", exc)
290288
return {"error": f"Search request failed: {exc}"}
291289
except ImportError as exc:

tests/unittests/tools/ardhf/test_ardhf_toolset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TestToolsetGetTools:
110110

111111
@pytest.mark.asyncio
112112
async def test_returns_all_tools(self):
113-
"""The toolset exposes all search aliases plus get_agent_card and connect_agent."""
113+
"""All seven tools are exposed by default."""
114114
toolset = AgentFinderToolset()
115115

116116
tools = await toolset.get_tools()
@@ -504,11 +504,11 @@ async def mock_send_message(**kwargs):
504504
patch(
505505
"a2a.client.card_resolver.A2ACardResolver",
506506
return_value=mock_resolver,
507-
) as _,
507+
),
508508
patch(
509509
"a2a.client.client_factory.ClientFactory",
510510
return_value=mock_factory,
511-
) as _,
511+
),
512512
):
513513
result = await connect_tool.run_async(
514514
args={

0 commit comments

Comments
 (0)