{"record":{"id":"2bedd4d19d5cb7ef","repo":"nodejs/node","slug":"invalid-sdist-filename-invalid-version-filenam","errorCode":null,"errorMessage":"Invalid sdist filename (invalid version): {filename}","messagePattern":"Invalid sdist filename \\(invalid version\\): (.+?)","errorType":"validation","errorClass":"InvalidSdistFilename","httpStatus":null,"severity":"error","filePath":"tools/gyp/pylib/packaging/utils.py","lineNumber":168,"sourceCode":"        file_stem = filename[: -len(\".zip\")]\n    else:\n        raise InvalidSdistFilename(\n            f\"Invalid sdist filename (extension must be '.tar.gz' or '.zip'):\"\n            f\" {filename}\"\n        )\n\n    # We are requiring a PEP 440 version, which cannot contain dashes,\n    # so we split on the last dash.\n    name_part, sep, version_part = file_stem.rpartition(\"-\")\n    if not sep:\n        raise InvalidSdistFilename(f\"Invalid sdist filename: {filename}\")\n\n    name = canonicalize_name(name_part)\n\n    try:\n        version = Version(version_part)\n    except InvalidVersion as e:\n        raise InvalidSdistFilename(\n            f\"Invalid sdist filename (invalid version): {filename}\"\n        ) from e\n\n    return (name, version)\n","sourceCodeStart":150,"sourceCodeEnd":173,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/gyp/pylib/packaging/utils.py#L150-L173","documentation":"InvalidSdistFilename raised when the version component (after the last dash) fails to parse as a PEP 440 Version; the inner InvalidVersion is chained via 'from e'.","triggerScenarios":"An sdist whose version segment is non-PEP-440 (e.g. 'mypkg-latest.tar.gz', 'mypkg-1.0.beta.extra.tar.gz' with disallowed syntax).","commonSituations":"Custom version strings, date-based versions not in PEP 440 form, or filenames where the dash-split put part of the name into the version slot (e.g. a name containing a dash, since sdist names do not escape dashes the way wheel names do).","solutions":["Use a PEP 440 compliant version string in the project.","If the project name contains a dash, note sdist filenames do not escape it - this can mislead the splitter; rely on the canonical version from project metadata instead.","Inspect __cause__ (InvalidVersion) for the precise parse failure."],"exampleFix":"# before (non-PEP-440 version)\n# 'mypkg-jan2024.tar.gz'\n\n# after\n# 'mypkg-1.0.0.tar.gz'","handlingStrategy":"validation","validationCode":"from packaging.version import Version, InvalidVersion\ndef sdist_version_valid(filename: str) -> bool:\n    if filename.endswith('.tar.gz'):\n        stem = filename[:-7]\n    elif filename.endswith('.zip'):\n        stem = filename[:-4]\n    else:\n        return False\n    _, sep, ver = stem.rpartition('-')\n    if not sep:\n        return False\n    try:\n        Version(ver)\n        return True\n    except InvalidVersion:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    name, ver = parse_sdist_filename(fn)\nexcept InvalidSdistFilename as e:\n    cause = e.__cause__  # InvalidVersion\n    # fix version string, rebuild","preventionTips":["Use PEP 440 versions.","Avoid dashes in sdist project names (they confuse the splitter).","Derive version from project metadata, not filenames."],"tags":["packaging","utils","sdist","version","pep440"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}