fix(ci): treat only a NAME_UNKNOWN 404 as an image with no tags

next_image_version.py read any 404 on the first tags/list page as a
repository not pushed yet, so a wrong registry path or a proxy's 404 page
would restart the image at <base>.0 instead of failing. The OCI
distribution spec answers a missing repository with 404 and the error
code NAME_UNKNOWN, so only that answer now means no tags.

RegistryError carried only the readable text of the body, so it now also
carries the body's OCI error codes. The tests cover a plain 404 page and a
404 with another code, both of which now raise.

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-12-02 08:51:21 +00:00
1 parent 6fee0ea8b2
commit a48cd063ea
2 files changed
+31 -4

No files matched your search

+16 -4
View File
@@ -70,9 +70,18 @@ USER_AGENT = "kamino-next-image-version"
class RegistryError(Exception):
def __init__(self, url, status, text, challenge=""):
def __init__(self, url, status, text, challenge="", codes=()):
super().__init__(f"GET {url}: HTTP {status}: {text}")
self.status, self.challenge = status, challenge
self.status, self.challenge, self.codes = status, challenge, codes
def _error_codes(raw):
"""The OCI error codes of an error body (`{"errors": [{"code": ...}]}`), or () for any other body."""
try:
errors = json.loads(raw).get("errors") or []
return tuple(e.get("code") for e in errors if isinstance(e, dict))
except (ValueError, AttributeError, TypeError):
return ()
def _readable(raw):
@@ -92,7 +101,9 @@ def _fetch(url, headers):
except urllib.error.HTTPError as exc:
raw = exc.read(20000).decode("utf-8", errors="replace")
challenge = exc.headers.get("WWW-Authenticate", "")
raise RegistryError(url, exc.code, _readable(raw), challenge) from exc
raise RegistryError(
url, exc.code, _readable(raw), challenge, _error_codes(raw)
) from exc
class Registry:
@@ -139,7 +150,8 @@ class Registry:
body, headers = self._get(path)
except RegistryError as exc:
# A repository not pushed yet is 404 NAME_UNKNOWN (OCI distribution spec): no tags.
if exc.status == 404 and not tags:
# Any other 404, such as a wrong registry path, must fail rather than restart at .0.
if exc.status == 404 and "NAME_UNKNOWN" in exc.codes and not tags:
return []
raise
tags += body.get("tags") or []