dotnet/aspnetcore · error · ValueError
Invalid Debian version format: {version}
Error message
Invalid Debian version format: {version} What it means
parse_debian_version applies the regex ^(?:(\d+):)?([^-]+)(?:-(.+))?$ to a version string and raises ValueError if it does not match. This parser underpins compare_debian_versions used to pick the highest version of each package from the index. Debian versions are normally epoch:upstream-revision, but malformed entries (empty string, version starting with '-', containing only a hyphen, etc.) break the regex.
Source
Thrown at eng/common/cross/install-debs.py:160
def parse_release_file(content, path):
"""Parses the Release file and returns sha256 checksum of the specified path."""
# data looks like this:
# <checksum> <size> <path>
matches = re.findall(r'^ (\S*) +(\S*) +(\S*)$', content, re.MULTILINE)
for entry in matches:
# the file has both md5 and sha256 checksums, we want sha256 which has a length of 64
if entry[2] == path and len(entry[0]) == 64:
return entry[0]
raise Exception(f"Could not find checksum for {path} in Release file.")
def parse_debian_version(version):
"""Parse a Debian package version into epoch, upstream version, and revision."""
match = re.match(r'^(?:(\d+):)?([^-]+)(?:-(.+))?$', version)
if not match:
raise ValueError(f"Invalid Debian version format: {version}")
epoch, upstream, revision = match.groups()
return int(epoch) if epoch else 0, upstream, revision or ""
def compare_upstream_version(v1, v2):
"""Compare upstream or revision parts using Debian rules."""
def tokenize(version):
tokens = re.split(r'([0-9]+|[A-Za-z]+)', version)
return [int(x) if x.isdigit() else x for x in tokens if x]
tokens1 = tokenize(v1)
tokens2 = tokenize(v2)
for token1, token2 in zip(tokens1, tokens2):
if type(token1) == type(token2):
if token1 != token2:
return (token1 > token2) - (token1 < token2)
else:
return -1 if isinstance(token1, str) else 1View on GitHub (pinned to 294cab2f9b)
Solutions
- Re-download the Packages.gz from a clean mirror — corruption during fetch is the usual cause.
- Verify the --mirror and --suite produce a well-formed Packages.gz (open it and grep for 'Version:' lines).
- If a single malformed package is to blame, exclude it from the requested package list or filter it before parse_package_index.
- Inspect the offending version string in the exception message to determine whether it is empty, hyphen-only, or otherwise non-Debian.
Example fix
# before — corrupt Packages.gz from a flaky mirror python3 install-debs.py --mirror http://bad-mirror/debian --suite sid ... # ValueError: Invalid Debian version format: # after python3 install-debs.py --mirror http://deb.debian.org/debian --suite sid ...
Defensive patterns
Strategy: validation
Validate before calling
# Pre-validate version strings before feeding them to compare_debian_versions
import re
DEB_VERSION_RE = re.compile(r'^(?:(\d+):)?([^-]+)(?:-(.+))?$')
def is_valid_debian_version(v: str) -> bool:
return bool(v) and bool(DEB_VERSION_RE.match(v))
for name, info in packages.items():
v = info.get('Version')
if not is_valid_debian_version(v):
print(f'Skipping {name}: malformed Version {v!r}')
continue Type guard
import re
_DEB_VERSION_RE = re.compile(r'^(?:(\d+):)?([^-]+)(?:-(.+))?$')
def is_valid_debian_version(v: object) -> bool:
return isinstance(v, str) and bool(v) and bool(_DEB_VERSION_RE.match(v)) Try / catch
try:
epoch, upstream, revision = parse_debian_version(version)
except ValueError as e:
if 'Invalid Debian version format' in str(e):
print(f'Skipping entry with malformed version {version!r}; re-download Packages.gz')
continue
raise Prevention
- Re-download Packages.gz from a clean mirror if versions look malformed.
- Validate Version fields before comparing to fail soft rather than aborting the whole build.
- Log offending versions to identify the corrupt mirror entry.
- Sanitize Versions from non-official repositories before parsing.
When it happens
Trigger: parse_package_index extracts Version fields from Packages.gz entries and calls compare_debian_versions whenever a package name already has a recorded version. If a mirror's Packages.gz contains a corrupt/empty Version field, the regex fails and ValueError is raised. Also triggered by manually feeding a non-Debian version string into the comparator.
Common situations: Corrupt or partial Packages.gz download that produced garbage Version fields; a mirror shipping a test/development package with a non-conformant version; an upstream package whose versioning violates Debian policy.
Related errors
- SHA256 mismatch for {url}: expected {checksum}, got {sha256}
- Failed to download {url}, Status Code: {response.status}
- Failed to download {url} after {max_retries} attempts.
- SHA256 mismatch for {path}: expected {packages_sha}, got {sh
- Signature verification failed: {result.stderr.decode('utf-8'
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/ea7261baa6c9cec3.
Report an issue: GitHub.