Dedicated error type for direct url parsing (#3181)

Add a dedicated error type for direct url parsing. This change is broken
out from the new uv requirement type, which uses direct url parsing
internally.
This commit is contained in:
konsti 2024-04-22 13:57:36 +02:00 committed by GitHub
parent 0e54cfb019
commit f29c991e21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 38 additions and 17 deletions

View file

@ -3,6 +3,7 @@ use tokio::task::JoinError;
use zip::result::ZipError;
use distribution_filename::WheelFilenameError;
use distribution_types::DirectUrlError;
use pep440_rs::Version;
use pypi_types::HashDigest;
use uv_client::BetterReqwestError;
@ -23,6 +24,8 @@ pub enum Error {
#[error("Git operation failed")]
Git(#[source] anyhow::Error),
#[error(transparent)]
DirectUrl(#[from] Box<DirectUrlError>),
#[error(transparent)]
Reqwest(#[from] BetterReqwestError),
#[error(transparent)]
Client(#[from] uv_client::Error),

View file

@ -67,7 +67,7 @@ pub(crate) async fn fetch_git_archive(
)
.map_err(Error::CacheWrite)?;
let DirectGitUrl { url, subdirectory } = DirectGitUrl::try_from(url).map_err(Error::Git)?;
let DirectGitUrl { url, subdirectory } = DirectGitUrl::try_from(url).map_err(Box::new)?;
// Fetch the Git repository.
let source = if let Some(reporter) = reporter {
@ -95,7 +95,7 @@ pub(crate) async fn resolve_precise(
cache: &Cache,
reporter: Option<&Arc<dyn Reporter>>,
) -> Result<Option<Url>, Error> {
let DirectGitUrl { url, subdirectory } = DirectGitUrl::try_from(url).map_err(Error::Git)?;
let DirectGitUrl { url, subdirectory } = DirectGitUrl::try_from(url).map_err(Box::new)?;
// If the Git reference already contains a complete SHA, short-circuit.
if url.precise().is_some() {