From a40d1f06b5609de951ef7f465d3a7946d986a613 Mon Sep 17 00:00:00 2001 From: Andrew Yim Date: Tue, 28 Apr 2026 07:54:47 +0900 Subject: [PATCH] fix(notion-search): make API errors non-fatal in search_candidates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Code review caught that without exception handling around notion.search() and notion.data_sources.query(), any transient API hiccup (rate limit, 5xx, network blip) would crash the whole search and lose candidates already accumulated from earlier variants/DBs. Wrap both calls in try/except, mirror the resolver's pattern: stderr warning + continue. Same query against another variant or another DB still has a chance to succeed. Also tightened response.get("results", []) → response.get("results") or [] so a hypothetical {"results": null} response doesn't crash the inner loop. 17/17 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../code/scripts/notion_search.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/custom-skills/31-notion-organizer/code/scripts/notion_search.py b/custom-skills/31-notion-organizer/code/scripts/notion_search.py index c08ef4a..8ce13b1 100644 --- a/custom-skills/31-notion-organizer/code/scripts/notion_search.py +++ b/custom-skills/31-notion-organizer/code/scripts/notion_search.py @@ -114,8 +114,13 @@ def search_candidates( if prop_filter: params["filter"] = prop_filter - response = notion.data_sources.query(**params) - for page in response.get("results", []): + try: + response = notion.data_sources.query(**params) + except Exception as exc: + print(f"Warning: query failed for database {db_id}: {exc}", + file=sys.stderr) + continue + for page in response.get("results") or []: page_id = page.get("id") if page_id and page_id not in seen_ids: seen_ids.add(page_id) @@ -124,8 +129,13 @@ def search_candidates( return candidates else: # Workspace-wide search - response = notion.search(query=query, page_size=100) - for item in response.get("results", []): + try: + response = notion.search(query=query, page_size=100) + except Exception as exc: + print(f"Warning: workspace search failed for variant {query!r}: {exc}", + file=sys.stderr) + continue + for item in response.get("results") or []: if item.get("object") != "page": continue page_id = item.get("id")