Building AI agents, atomically
Wrap aiohttp transport errors so the key never reaches a raised repr
Juampia64d126974bf
diff --git a/atomic-forge/tools/firecrawl_search/tests/test_firecrawl_search.py b/atomic-forge/tools/firecrawl_search/tests/test_firecrawl_search.pyindex f61e2a7..dba29bd 100644--- a/atomic-forge/tools/firecrawl_search/tests/test_firecrawl_search.py+++ b/atomic-forge/tools/firecrawl_search/tests/test_firecrawl_search.py@@ -318,6 +318,25 @@ async def test_http_non_json_error_page_reports_status():await _http_tool(base_url).run_async(FirecrawlSearchToolInputSchema(queries=["q"]))+async def test_http_transport_error_does_not_expose_key(caplog):+ """aiohttp's own errors (here a redirect loop) carry the request headers; the tool must not re-raise them as is."""++ def respond(body):+ return web.Response(status=307, headers={"Location": "/v2/search"})++ async with fake_firecrawl(respond) as (base_url, seen):+ with caplog.at_level(logging.WARNING, logger="tool.firecrawl_search"):+ with pytest.raises(Exception) as raised:+ await _http_tool(base_url).run_async(FirecrawlSearchToolInputSchema(queries=["q"]))++ assert len(seen) > 1+ assert "Firecrawl search failed for 'q': TooManyRedirects" in str(raised.value)+ assert raised.value.__cause__ is None+ for text in (str(raised.value), repr(raised.value), caplog.text):+ assert DUMMY_KEY not in text++@pytest.mark.asyncioasync def test_http_dummy_key_kept_out_of_repr_errors_and_logs(caplog):"""Even when the provider echoes the key back, it never reaches repr, raised errors, or logs."""diff --git a/atomic-forge/tools/firecrawl_search/tool/firecrawl_search.py b/atomic-forge/tools/firecrawl_search/tool/firecrawl_search.pyindex 11683d1..efdeed5 100644--- a/atomic-forge/tools/firecrawl_search/tool/firecrawl_search.py+++ b/atomic-forge/tools/firecrawl_search/tool/firecrawl_search.py@@ -2,7 +2,7 @@ import asyncioimport loggingimport osfrom concurrent.futures import ThreadPoolExecutor-from typing import List, Literal, Optional+from typing import List, Literal, Optional, Unionimport aiohttpfrom pydantic import Field, SecretStr@@ -135,7 +135,7 @@ class FirecrawlSearchTool(BaseTool[FirecrawlSearchToolInputSchema, FirecrawlSeardef _redact(self, text: str) -> str:return text.replace(self._api_key, "[redacted]") if self._api_key else text- def _error(self, query: str, status: int, detail: str) -> Exception:+ def _error(self, query: str, status: Union[int, str], detail: Optional[str]) -> Exception:return Exception(self._redact(f"Firecrawl search failed for '{query}': {status} {detail}"))@staticmethod@@ -164,9 +164,13 @@ class FirecrawlSearchTool(BaseTool[FirecrawlSearchToolInputSchema, FirecrawlSearquery: str,params: FirecrawlSearchToolInputSchema,) -> List[FirecrawlSearchResultItem]:- async with session.post(f"{self.base_url}/search", json=self._build_body(query, params)) as resp:- data = await self._read_json(resp)- self._check_success(query, resp.status, resp.reason, data)+ try:+ async with session.post(f"{self.base_url}/search", json=self._build_body(query, params)) as resp:+ data = await self._read_json(resp)+ self._check_success(query, resp.status, resp.reason, data)+ except aiohttp.ClientError as error:+ # aiohttp errors such as TooManyRedirects carry the request headers, Authorization included, in their repr.+ raise self._error(query, type(error).__name__, str(error)) from Nonehits = self._extract_hits(query, data, params.search_type)items = [self._to_item(hit, query, self.max_content_chars) for hit in hits if isinstance(hit, dict) and hit.get("url")]