From 1caa36ad22126f0c8d853452e4db58f8d51b43f1 Mon Sep 17 00:00:00 2001 From: Lucenx9 <185146821+Lucenx9@users.noreply.github.com> Date: Sun, 8 Mar 2026 01:04:16 +0100 Subject: [PATCH] Fix minor robustness issues found during code audit - Guard go.mod version parsing against malformed lines missing a version field (IndexError on split) - Replace assert with explicit error return in _sync_single_router so the check is not stripped by python -O Co-Authored-By: Claude Opus 4.6 --- agentinit/_project_detect.py | 4 +++- agentinit/_sync.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/agentinit/_project_detect.py b/agentinit/_project_detect.py index 6ad9492..148236f 100644 --- a/agentinit/_project_detect.py +++ b/agentinit/_project_detect.py @@ -361,7 +361,9 @@ def _run_detect(dest, project_path, content): for line in f: line = line.strip() if line.startswith("go "): - go_version = line.split(" ")[1] + parts = line.split() + if len(parts) >= 2: + go_version = parts[1] break stack_updates["- **Language(s):** (not configured)"] = ( diff --git a/agentinit/_sync.py b/agentinit/_sync.py index 48423d9..20723d5 100644 --- a/agentinit/_sync.py +++ b/agentinit/_sync.py @@ -142,7 +142,8 @@ def _sync_single_router( expected, read_error = _read_text(template_path, "template") if read_error: return "error", read_error - assert expected is not None + if expected is None: + return "error", "template read failed" current = None if os.path.isfile(dst):