Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for invalid sdist archives #1389

Merged
merged 2 commits into from
Feb 16, 2024

Conversation

robin-nitrokey
Copy link
Contributor

This PR improves the error message for the problem described in #1376. The original output duplicates the actual error message and includes lots of noise (DirEntry { inner: DirEntry(...) }).

$ uv pip install hexdump==3.3
error: Failed to download and build: hexdump==3.3
  Caused by: Failed to extract source distribution: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/__main__.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/hexdump.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/data") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/PKG-INFO") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/setup.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/README.txt") }]
  Caused by: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/__main__.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/hexdump.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/data") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/PKG-INFO") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/setup.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpgSvTCk/README.txt") }]

This PR removes the duplication and DirEntry internals so that the error message is easier to grasp:

$ uv pip install hexdump==3.3
error: Failed to download and build: hexdump==3.3
  Caused by: Failed to extract source distribution
  Caused by: The top level of the archive must only contain a list directory, but it contains: ["__main__.py", "hexdump.py", "data", "PKG-INFO", "setup.py", "README.txt"]

Previously, the uv_extract::Error was used as the source and in the
message for the uv_distribution::Error::Extract variant.  This led to
duplicated error messages like:

  Caused by: Failed to extract source distribution: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/__main__.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/hexdump.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/data") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/PKG-INFO") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/setup.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/README.txt") }]
  Caused by: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/__main__.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/hexdump.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/data") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/PKG-INFO") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/setup.py") }, DirEntry { inner: DirEntry("/home/user/.cache/uv/.tmphnfEex/README.txt") }]

This patch removes the source error from the error message so the inner
error is only displayed once:

  Caused by: Failed to extract source distribution
  Caused by: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/__main__.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/hexdump.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/data") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/PKG-INFO") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/setup.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/README.txt") }
Previously, the InvalidArchive error variant included the DirEntry
instances for all files in the unzipped directory.  This leads to a very
verbose error message even if the only relevant information is the name
of the files in the directory:

  Caused by: The top level of the archive must only contain a list directory, but it contains: [DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/__main__.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/hexdump.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/data") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/PKG-INFO") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/setup.py") }, DirEntry { inner: DirEntry("/home/robin/.cache/uv/.tmpPLyqMo/README.txt") }]

This patch replaces the DirEntry with the file name so that the error
message is much more concise with the same information:

  Caused by: The top level of the archive must only contain a list directory, but it contains: ["__main__.py", "hexdump.py", "data", "PKG-INFO", "setup.py", "README.txt"]
@zanieb zanieb added the error messages Messaging when something goes wrong label Feb 15, 2024
@zanieb zanieb self-requested a review February 15, 2024 23:50
@zanieb
Copy link
Member

zanieb commented Feb 15, 2024

Thanks so much for contributing!

@zanieb zanieb merged commit f9a9f53 into astral-sh:main Feb 16, 2024
7 checks passed
@robin-nitrokey robin-nitrokey deleted the invalid-archive-error branch February 16, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Messaging when something goes wrong
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants