Skip to content

Commit 7776e88

Browse files
committed
fix: address gemini-code-assist 12th review on PR #1
All 5 findings legitimate, all applied: Defensive exception handling: - collect_github._get_page: add ValueError to except. urlopen raises it for malformed URLs ("unknown url type" etc.), e.g. a sources.yaml entry with a missing scheme. [MEDIUM] - collect_rss._fetch: same ValueError addition. [MEDIUM] - score.score: wrap json.loads(normalized.json) in try/except. A corrupt or truncated file (disk-full mid-write etc.) used to crash the whole scoring step instead of leaving the previous scored.json in place. [MEDIUM] - report.render: same try/except around json.loads(scored.json). [MEDIUM] Stale guidance: - new-track.sh: the "next steps" message still told users to edit TRACKS in the root Makefile, but Makefile now auto-discovers tracks via `wildcard tracks/*/`. Updated to point at the two places that do still need a manual update for a new track: .github/workflows/{daily-update,weekly-digest}.yml matrix.track web/src/lib/data.ts TRACKS const with a footnote that the root Makefile is auto. [MEDIUM]
1 parent 1eaebb6 commit 7776e88

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

scripts/awsdd/collect_github.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def _get_page(url: str) -> tuple[list[dict], str | None]:
6767
except HTTPError as e:
6868
print(f"[collect_github] {url}: HTTP {e.code}")
6969
return [], None
70-
except (URLError, TimeoutError, UnicodeDecodeError, json.JSONDecodeError) as e:
70+
except (URLError, TimeoutError, UnicodeDecodeError, ValueError, json.JSONDecodeError) as e:
71+
# ValueError covers urlopen's "unknown url type" / malformed-URL path
72+
# in case sources.yaml smuggles in an unsupported scheme.
7173
print(f"[collect_github] {url}: error {e}")
7274
return [], None
7375
# GitHub returns a JSON object (not a list) on error envelopes (rate-limit etc.);

scripts/awsdd/collect_rss.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def _fetch(url: str, timeout: int = FETCH_TIMEOUT) -> bytes | None:
4747
# truncated XML body to feedparser would just bozo-error silently
4848
# and partially populate the track. Better to skip the feed loudly.
4949
raw = r.read(MAX_FEED_BYTES + 1)
50-
except (URLError, TimeoutError) as e:
50+
except (URLError, TimeoutError, ValueError) as e:
51+
# ValueError catches urlopen's "unknown url type" path so a typo in
52+
# sources.yaml (missing scheme, etc.) doesn't crash the whole track.
5153
print(f"[collect_rss] fetch {url}: {e}")
5254
return None
5355
if len(raw) > MAX_FEED_BYTES:

scripts/awsdd/report.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ def _filename(mode: str, now: datetime) -> str:
2020

2121
def render(track: str, mode: str) -> None:
2222
p = track_dir(track) / "data" / "scored.json"
23-
items: list[dict] = json.loads(p.read_text(encoding="utf-8")) if p.exists() else []
23+
items: list[dict] = []
24+
if p.exists():
25+
try:
26+
items = json.loads(p.read_text(encoding="utf-8"))
27+
except (OSError, json.JSONDecodeError) as e:
28+
print(f"[report] {track}: failed to load scored.json: {e}")
2429
now = datetime.now(UTC)
2530
cutoff = now - WINDOW[mode]
2631
fresh = [it for it in items if parse_iso(it.get("published_at", "")) >= cutoff]

scripts/awsdd/score.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ def score_item(item: dict, sources: dict, now: datetime) -> dict[str, float]:
6969

7070
def score(track: str) -> None:
7171
p = track_dir(track) / "data" / "normalized.json"
72-
items: list[dict] = json.loads(p.read_text(encoding="utf-8")) if p.exists() else []
72+
items: list[dict] = []
73+
if p.exists():
74+
try:
75+
items = json.loads(p.read_text(encoding="utf-8"))
76+
except (OSError, json.JSONDecodeError) as e:
77+
print(f"[score] {track}: failed to load normalized.json: {e}")
7378
sources = load_sources(track)
7479
now = datetime.now(UTC)
7580
for it in items:

scripts/new-track.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ fi
2525
echo "Created tracks/$name"
2626
echo "Next:"
2727
echo " 1. edit tracks/$name/config/sources.yaml"
28-
echo " 2. add '$name' to TRACKS in Makefile and to matrix.track in .github/workflows/*.yml"
29-
echo " 3. make -C tracks/$name install update"
28+
echo " 2. add '$name' to matrix.track in .github/workflows/daily-update.yml and weekly-digest.yml"
29+
echo " 3. add '$name' to TRACKS in web/src/lib/data.ts so the site renders it"
30+
echo " 4. make -C tracks/$name install update"
31+
echo "(The root Makefile auto-discovers tracks via wildcard, no edit needed.)"

0 commit comments

Comments
 (0)