mirror of https://github.com/astral-sh/uv
Improve error message for invalid sdist archives (#1389)
This PR improves the error message for the problem described in https://github.com/astral-sh/uv/issues/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"] ```
This commit is contained in:
parent
c6a43e92f9
commit
f9a9f53476
|
|
@ -53,7 +53,7 @@ pub enum Error {
|
|||
Zip(#[from] ZipError),
|
||||
#[error("Source distribution directory contains neither readable pyproject.toml nor setup.py")]
|
||||
DirWithoutEntrypoint,
|
||||
#[error("Failed to extract source distribution: {0}")]
|
||||
#[error("Failed to extract source distribution")]
|
||||
Extract(#[from] uv_extract::Error),
|
||||
|
||||
/// Should not occur; only seen when another task panicked.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::{ffi::OsString, path::PathBuf};
|
||||
|
||||
use zip::result::ZipError;
|
||||
|
||||
|
|
@ -15,5 +15,5 @@ pub enum Error {
|
|||
#[error(
|
||||
"The top level of the archive must only contain a list directory, but it contains: {0:?}"
|
||||
)]
|
||||
InvalidArchive(Vec<fs_err::DirEntry>),
|
||||
InvalidArchive(Vec<OsString>),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,9 @@ pub fn strip_component(source: impl AsRef<Path>) -> Result<PathBuf, Error> {
|
|||
let top_level =
|
||||
fs_err::read_dir(source.as_ref())?.collect::<std::io::Result<Vec<fs_err::DirEntry>>>()?;
|
||||
let [root] = top_level.as_slice() else {
|
||||
return Err(Error::InvalidArchive(top_level));
|
||||
return Err(Error::InvalidArchive(
|
||||
top_level.into_iter().map(|e| e.file_name()).collect(),
|
||||
));
|
||||
};
|
||||
Ok(root.path())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue