fix: distinguish consistency API lookup failures

This commit is contained in:
2026-06-07 13:53:34 +02:00
parent a3c3bbe149
commit b3f8ed63c2
2 changed files with 68 additions and 5 deletions

View File

@@ -483,9 +483,15 @@ def _inject_task_id_frontmatter_list(
# API helpers
# ---------------------------------------------------------------------------
def _api_get(api_base: str, path: str, params: dict | None = None) -> Any:
def _api_get(
api_base: str,
path: str,
params: dict | None = None,
*,
return_error: bool = False,
) -> Any:
if not _HAS_HTTPX:
return None
return {"_error": "httpx is not installed"} if return_error else None
# Only append trailing slash to the path component, not to query strings
if "?" not in path and not path.endswith("/"):
path += "/"
@@ -495,7 +501,15 @@ def _api_get(api_base: str, path: str, params: dict | None = None) -> Any:
r = c.get(path, params=filtered if filtered else None)
r.raise_for_status()
return r.json()
except Exception:
except _httpx.HTTPStatusError as exc:
if exc.response.status_code == 404:
return None
if return_error:
return {"_error": str(exc)}
return None
except Exception as exc:
if return_error:
return {"_error": str(exc)}
return None
@@ -629,7 +643,17 @@ def _infer_slug_from_path(api_base: str, path: str) -> "tuple[str, str] | None":
def check_repo(api_base: str, repo_slug: str, repo_path_override: str | None = None) -> ConsistencyReport:
"""Run all consistency checks for a registered repo."""
repo = _api_get(api_base, f"/repos/{repo_slug}")
repo = _api_get(api_base, f"/repos/{repo_slug}", return_error=True)
if isinstance(repo, dict) and "_error" in repo:
report = ConsistencyReport(repo_slug=repo_slug, repo_path=repo_path_override or "(unknown)")
report.add(
severity="FAIL", check_id="C-00",
message=(
f"Could not query State Hub API at {api_base}: {repo['_error']}"
),
fixable=False,
)
return report
if repo is None:
report = ConsistencyReport(repo_slug=repo_slug, repo_path="(unknown)")
report.add(
@@ -1528,6 +1552,8 @@ def fix_repo(
) -> ConsistencyReport:
"""Run checks then apply all auto-fixable issues. Returns updated report."""
report = check_repo(api_base, repo_slug, repo_path_override)
if any(i.check_id == "C-00" for i in report.failures):
return report
# Auto-register this machine's path in host_paths so future runs work
# without --repo-path. Idempotent: skipped when already correct.