From 0d6bf5793255db93ef7a598664111d049280b761 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Mon, 25 May 2026 20:00:18 +0200 Subject: [PATCH] fix: handle empty/invalid athlete.json in merge, API read, and writer encoding --- bincio/extract/writer.py | 4 +++- bincio/serve/routers/activities.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bincio/extract/writer.py b/bincio/extract/writer.py index f4bd98d..512b263 100644 --- a/bincio/extract/writer.py +++ b/bincio/extract/writer.py @@ -382,7 +382,9 @@ def write_athlete_json(summaries: list[dict], output_dir: Path, athlete_config: **athlete_config, } (output_dir / "athlete.json").write_text( - json.dumps(athlete, indent=2, ensure_ascii=False) + json.dumps(athlete, indent=2, ensure_ascii=False), + encoding="utf-8", + errors="replace", ) diff --git a/bincio/serve/routers/activities.py b/bincio/serve/routers/activities.py index 143021b..2cc36fa 100644 --- a/bincio/serve/routers/activities.py +++ b/bincio/serve/routers/activities.py @@ -285,7 +285,10 @@ async def get_athlete(bincio_session: str | None = Cookie(default=None)) -> JSON athlete_path = dd / "athlete.json" data: dict = {} if athlete_path.exists(): - data = json.loads(athlete_path.read_text(encoding="utf-8")) + try: + data = json.loads(athlete_path.read_text(encoding="utf-8")) + except (json.JSONDecodeError, OSError): + pass # Layer edits/athlete.yaml on top edits_path = dd / "edits" / "athlete.yaml" if edits_path.exists():