Improve error message when editable requirement doesn't exist (#1024)

Making these a lot clearer in the common case by reducing the depth of
the error.
This commit is contained in:
Charlie Marsh 2024-01-20 12:59:18 -05:00 committed by GitHub
parent 53b7e3cb4f
commit d9cc9dbf88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 34 additions and 18 deletions

View file

@ -11,6 +11,6 @@ pub enum Error {
#[error("Unable to extract filename from URL: {0}")]
UrlFilename(Url),
#[error("Unable to locate distribution at: {0}")]
NotFound(Url, #[source] std::io::Error),
#[error("Distribution not found at: {0}")]
NotFound(Url),
}

View file

@ -228,12 +228,19 @@ impl Dist {
}
if url.scheme().eq_ignore_ascii_case("file") {
// Store the canonicalized path.
let path = url
// Store the canonicalized path, which also serves to validate that it exists.
let path = match url
.to_file_path()
.map_err(|()| Error::UrlFilename(url.to_url()))?
.canonicalize()
.map_err(|err| Error::NotFound(url.to_url(), err))?;
{
Ok(path) => path,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Err(Error::NotFound(url.to_url()));
}
Err(err) => return Err(err.into()),
};
return if path
.extension()
.is_some_and(|ext| ext.eq_ignore_ascii_case("whl"))