{"record":{"id":"d01484d0da7ff623","repo":"dotnet/maui","slug":"invalid-debian-version-format-version","errorCode":null,"errorMessage":"Invalid Debian version format: {version}","messagePattern":"Invalid Debian version format: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"eng/common/cross/install-debs.py","lineNumber":99,"sourceCode":"    \"\"\"Fetch and decompress the Packages.gz file.\"\"\"\n    try:\n        async with session.get(url) as response:\n            if response.status == 200:\n                compressed_data = await response.read()\n                decompressed_data = gzip.decompress(compressed_data).decode('utf-8')\n                print(f\"Downloaded index: {url}\")\n                return decompressed_data\n            else:\n                print(f\"Skipped index: {url} (doesn't exist)\")\n                return None\n    except Exception as e:\n        print(f\"Error fetching {url}: {e}\")\n\ndef parse_debian_version(version):\n    \"\"\"Parse a Debian package version into epoch, upstream version, and revision.\"\"\"\n    match = re.match(r'^(?:(\\d+):)?([^-]+)(?:-(.+))?$', version)\n    if not match:\n        raise ValueError(f\"Invalid Debian version format: {version}\")\n    epoch, upstream, revision = match.groups()\n    return int(epoch) if epoch else 0, upstream, revision or \"\"\n\ndef compare_upstream_version(v1, v2):\n    \"\"\"Compare upstream or revision parts using Debian rules.\"\"\"\n    def tokenize(version):\n        tokens = re.split(r'([0-9]+|[A-Za-z]+)', version)\n        return [int(x) if x.isdigit() else x for x in tokens if x]\n\n    tokens1 = tokenize(v1)\n    tokens2 = tokenize(v2)\n\n    for token1, token2 in zip(tokens1, tokens2):\n        if type(token1) == type(token2):\n            if token1 != token2:\n                return (token1 > token2) - (token1 < token2)\n        else:\n            return -1 if isinstance(token1, str) else 1","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/common/cross/install-debs.py#L81-L117","documentation":"parse_debian_version raises ValueError when the supplied version string does not match the Debian version regex `^(?:(\\d+):)?([^-]+)(?:-(.+))$` (optional epoch, non-empty upstream, optional revision). The parser is used to compare package versions when selecting debs for a cross-build rootfs; an unparseable version halts rootfs setup.","triggerScenarios":"Passing a malformed version to parse_debian_version: empty string, a string starting with '-', a revision-only fragment, or a version containing characters the regex rejects in the upstream segment. Triggered when the Packages index contains an unexpected version field.","commonSituations":"A mirror returns a Packages index with non-standard versions, a hand-edited version list, or a proxy/cache that mangles the version string.","solutions":["Inspect the version string passed in; ensure it matches epoch:upstream-revision form (e.g. `1:1.2.3-4`).","If the index is malformed, switch --mirror to the official Debian/Ubuntu mirror or clear the cached index.","Wrap the call and skip/log packages whose versions fail to parse rather than aborting the whole rootfs.","Pin --suite to a stable release whose package versions are well-formed."],"exampleFix":"# before\nepoch, upstream, rev = parse_debian_version(bad_version)\n\n# after\nimport re\nif not re.match(r'^(?:(\\d+):)?([^-]+)(?:-(.+))?$', bad_version):\n    print(f\"Skipping malformed version: {bad_version}\"); continue\nepoch, upstream, rev = parse_debian_version(bad_version)","handlingStrategy":"validation","validationCode":"import re\nif not re.match(r'^(?:(\\d+):)?([^-]+)(?:-(.+))?$', version):\n    raise ValueError(f\"Invalid Debian version format: {version}\")","typeGuard":"import re\ndef is_valid_debian_version(v): return bool(re.match(r'^(?:(\\d+):)?([^-]+)(?:-(.+))?$', v))","tryCatchPattern":"try:\n    epoch, up, rev = parse_debian_version(v)\nexcept ValueError as e:\n    print(f\"skip {v}: {e}\"); continue","preventionTips":["Validate versions against the regex before parsing.","Switch to an official mirror if the index is malformed.","Skip and log unparseable versions rather than aborting rootfs setup."],"tags":["python","cross-build","rootfs","debian"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}