{"record":{"id":"f35553890fad00fe","repo":"nodejs/node","slug":"invalid-version-version","errorCode":null,"errorMessage":"Invalid version: '{version}'","messagePattern":"Invalid version: '(.+?)'","errorType":"validation","errorClass":"InvalidVersion","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/packaging/version.py","lineNumber":200,"sourceCode":"\n    _regex = re.compile(r\"^\\s*\" + VERSION_PATTERN + r\"\\s*$\", re.VERBOSE | re.IGNORECASE)\n    _key: CmpKey\n\n    def __init__(self, version: str) -> None:\n        \"\"\"Initialize a Version object.\n\n        :param version:\n            The string representation of a version which will be parsed and normalized\n            before use.\n        :raises InvalidVersion:\n            If the ``version`` does not conform to PEP 440 in any way then this\n            exception will be raised.\n        \"\"\"\n\n        # Validate the version and parse it into pieces\n        match = self._regex.search(version)\n        if not match:\n            raise InvalidVersion(f\"Invalid version: '{version}'\")\n\n        # Store the parsed out pieces of the version\n        self._version = _Version(\n            epoch=int(match.group(\"epoch\")) if match.group(\"epoch\") else 0,\n            release=tuple(int(i) for i in match.group(\"release\").split(\".\")),\n            pre=_parse_letter_version(match.group(\"pre_l\"), match.group(\"pre_n\")),\n            post=_parse_letter_version(\n                match.group(\"post_l\"), match.group(\"post_n1\") or match.group(\"post_n2\")\n            ),\n            dev=_parse_letter_version(match.group(\"dev_l\"), match.group(\"dev_n\")),\n            local=_parse_local_version(match.group(\"local\")),\n        )\n\n        # Generate a key which will be used for sorting\n        self._key = _cmpkey(\n            self._version.epoch,\n            self._version.release,\n            self._version.pre,","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/packaging/version.py#L182-L218","documentation":"packaging.version.InvalidVersion raised by Version.__init__ when the version string does not match the PEP 440 regex even after the library's lenient normalization search. This is the canonical 'not a valid version' error for the whole packaging library and underpins several wheel/sdist filename errors.","triggerScenarios":"Constructing Version('v1.0'), Version('1..0'), Version('1.0-beta'), or other non-PEP-440 strings raises. The regex uses .search() so a valid substring embedded in junk may slip through, but fully non-conforming strings fail.","commonSituations":"Parsing VCS tags (e.g. 'v1.0'), SCM-generated versions, date-only versions, or versions from languages with looser schemes (e.g. SemVer-with-build that PEP 440 rejects).","solutions":["Strip leading 'v' and normalize the version to PEP 440 before constructing Version.","Use packaging.version.parse() which tolerates legacy versions instead of strict Version().","Catch InvalidVersion at the input boundary and report the offending string."],"exampleFix":"# before\nv = Version(tag)  # tag = 'v1.0'\n\n# after\nfrom packaging.version import parse\nv = parse(tag.lstrip('v'))","handlingStrategy":"validation","validationCode":"from packaging.version import Version, InvalidVersion\ndef is_pep440(version: str) -> bool:\n    try:\n        Version(version)\n        return True\n    except InvalidVersion:\n        return False","typeGuard":"from packaging.version import Version\ndef as_version(v):\n    try:\n        return Version(v)\n    except InvalidVersion:\n        return None","tryCatchPattern":"from packaging.version import parse, Version, InvalidVersion\ntry:\n    v = Version(raw)\nexcept InvalidVersion:\n    v = parse(raw)  # tolerates legacy forms","preventionTips":["Normalize VCS tags (strip 'v' prefix) before constructing Version.","Use packaging.version.parse() for tolerant parsing.","Validate versions at the input boundary."],"tags":["packaging","version","pep440","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}