Use display representation for download error (#5173)

## Summary

Turns out we already have display for this.

Closes https://github.com/astral-sh/uv/issues/4914.
This commit is contained in:
Charlie Marsh 2024-07-17 22:05:17 -04:00 committed by GitHub
parent 91bf213641
commit 564f4b2958
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 8 deletions

1
Cargo.lock generated
View file

@ -4934,6 +4934,7 @@ dependencies = [
"install-wheel-rs",
"itertools 0.13.0",
"once_cell",
"owo-colors",
"pep440_rs",
"pep508_rs",
"platform-tags",

View file

@ -34,6 +34,7 @@ fs-err = { workspace = true, features = ["tokio"] }
futures = { workspace = true }
itertools = { workspace = true }
once_cell = { workspace = true }
owo-colors = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }

View file

@ -6,6 +6,7 @@ use std::str::FromStr;
use std::task::{Context, Poll};
use futures::TryStreamExt;
use owo_colors::OwoColorize;
use thiserror::Error;
use tokio::io::{AsyncRead, ReadBuf};
use tokio_util::compat::FuturesAsyncReadCompatExt;
@ -30,9 +31,9 @@ pub enum Error {
IO(#[from] io::Error),
#[error(transparent)]
ImplementationError(#[from] ImplementationError),
#[error("Invalid python version: {0}")]
#[error("Invalid Python version: {0}")]
InvalidPythonVersion(String),
#[error("Invalid request key, too many parts: {0}")]
#[error("Invalid request key (too many parts): {0}")]
TooManyParts(String),
#[error("Download failed")]
NetworkError(#[from] WrappedReqwestError),
@ -48,7 +49,7 @@ pub enum Error {
expected: String,
actual: String,
},
#[error("Invalid download url")]
#[error("Invalid download URL")]
InvalidUrl(#[from] url::ParseError),
#[error("Failed to create download directory")]
DownloadDirError(#[source] io::Error),
@ -64,12 +65,9 @@ pub enum Error {
#[source]
err: io::Error,
},
#[error("Failed to parse managed Python directory name: {0}")]
NameError(String),
#[error("Failed to parse request part")]
InvalidRequestPlatform(#[from] platform::Error),
// TODO(zanieb): Implement display for `PythonDownloadRequest`
#[error("No download found for request: {0:?}")]
#[error("No download found for request: {}", _0.green())]
NoDownloadFound(PythonDownloadRequest),
}

View file

@ -91,7 +91,7 @@ pub(crate) async fn install(
.find(|installation| download_request.satisfied_by_key(installation.key()))
{
if matches!(request, PythonRequest::Any) {
writeln!(printer.stderr(), "Found: {}", installation.key().green(),)?;
writeln!(printer.stderr(), "Found: {}", installation.key().green())?;
} else {
writeln!(
printer.stderr(),