mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Improve non-git error message (#3403)
The boxing changes are due to clippy
This commit is contained in:
parent
d0c3146ef6
commit
098944fc7d
12 changed files with 36 additions and 18 deletions
|
@ -8,8 +8,12 @@ use uv_git::{GitSha, GitUrl};
|
|||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ParsedUrlError {
|
||||
#[error("Unsupported URL prefix `{prefix}` in URL: `{url}`")]
|
||||
UnsupportedUrlPrefix { prefix: String, url: Url },
|
||||
#[error("Unsupported URL prefix `{prefix}` in URL: `{url}` ({message})")]
|
||||
UnsupportedUrlPrefix {
|
||||
prefix: String,
|
||||
url: Url,
|
||||
message: &'static str,
|
||||
},
|
||||
#[error("Invalid path in file URL: `{0}`")]
|
||||
InvalidFileUrl(Url),
|
||||
#[error("Failed to parse Git reference from URL: `{0}`")]
|
||||
|
@ -123,9 +127,25 @@ impl TryFrom<Url> for ParsedUrl {
|
|||
if let Some((prefix, ..)) = url.scheme().split_once('+') {
|
||||
match prefix {
|
||||
"git" => Ok(Self::Git(ParsedGitUrl::try_from(url)?)),
|
||||
"bzr" => Err(ParsedUrlError::UnsupportedUrlPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
url: url.clone(),
|
||||
message: "Bazaar is not supported",
|
||||
}),
|
||||
"hg" => Err(ParsedUrlError::UnsupportedUrlPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
url: url.clone(),
|
||||
message: "Mercurial is not supported",
|
||||
}),
|
||||
"svn" => Err(ParsedUrlError::UnsupportedUrlPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
url: url.clone(),
|
||||
message: "Subversion is not supported",
|
||||
}),
|
||||
_ => Err(ParsedUrlError::UnsupportedUrlPrefix {
|
||||
prefix: prefix.to_string(),
|
||||
url: url.clone(),
|
||||
message: "Unknown scheme",
|
||||
}),
|
||||
}
|
||||
} else if url.scheme().eq_ignore_ascii_case("file") {
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Requirement {
|
|||
}
|
||||
|
||||
/// Convert a [`pep508_rs::Requirement`] to a [`Requirement`].
|
||||
pub fn from_pep508(requirement: pep508_rs::Requirement) -> Result<Self, ParsedUrlError> {
|
||||
pub fn from_pep508(requirement: pep508_rs::Requirement) -> Result<Self, Box<ParsedUrlError>> {
|
||||
let source = match requirement.version_or_url {
|
||||
None => RequirementSource::Registry {
|
||||
specifier: VersionSpecifiers::empty(),
|
||||
|
|
|
@ -59,7 +59,7 @@ impl UnresolvedRequirement {
|
|||
}
|
||||
|
||||
/// Return the version specifier or URL for the requirement.
|
||||
pub fn source(&self) -> Result<Cow<'_, RequirementSource>, ParsedUrlError> {
|
||||
pub fn source(&self) -> Result<Cow<'_, RequirementSource>, Box<ParsedUrlError>> {
|
||||
// TODO(konsti): This is a bad place to raise errors, we should have parsed the url earlier.
|
||||
match self {
|
||||
Self::Named(requirement) => Ok(Cow::Borrowed(&requirement.source)),
|
||||
|
|
|
@ -311,7 +311,7 @@ pub struct RequirementEntry {
|
|||
// `UnresolvedRequirementSpecification` is defined in `distribution-types` and `requirements-txt`
|
||||
// depends on `distribution-types`.
|
||||
impl TryFrom<RequirementEntry> for UnresolvedRequirementSpecification {
|
||||
type Error = ParsedUrlError;
|
||||
type Error = Box<ParsedUrlError>;
|
||||
|
||||
fn try_from(value: RequirementEntry) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
|
|
|
@ -105,7 +105,7 @@ pub enum Error {
|
|||
#[error("Failed to build PATH for build script")]
|
||||
BuildScriptPath(#[source] env::JoinPathsError),
|
||||
#[error("Failed to parse requirements from build backend")]
|
||||
DirectUrl(#[source] ParsedUrlError),
|
||||
DirectUrl(#[source] Box<ParsedUrlError>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -26,7 +26,7 @@ pub enum LookaheadError {
|
|||
#[error(transparent)]
|
||||
UnsupportedUrl(#[from] distribution_types::Error),
|
||||
#[error(transparent)]
|
||||
InvalidRequirement(#[from] distribution_types::ParsedUrlError),
|
||||
InvalidRequirement(#[from] Box<distribution_types::ParsedUrlError>),
|
||||
}
|
||||
|
||||
/// A resolver for resolving lookahead requirements from direct URLs.
|
||||
|
|
|
@ -407,7 +407,7 @@ pub(crate) fn lower_requirement(
|
|||
return if requirement.version_or_url.is_none() && &requirement.name != project_name {
|
||||
Err(LoweringError::UnconstrainedVersion)
|
||||
} else {
|
||||
Ok(Requirement::from_pep508(requirement).map_err(Box::new)?)
|
||||
Ok(Requirement::from_pep508(requirement)?)
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Preference {
|
|||
Ok(Self {
|
||||
requirement: match entry.requirement {
|
||||
RequirementsTxtRequirement::Named(requirement) => {
|
||||
Requirement::from_pep508(requirement).map_err(Box::new)?
|
||||
Requirement::from_pep508(requirement)?
|
||||
}
|
||||
RequirementsTxtRequirement::Unnamed(requirement) => {
|
||||
return Err(PreferenceError::Bare(requirement));
|
||||
|
|
|
@ -892,8 +892,7 @@ impl<
|
|||
.iter()
|
||||
.cloned()
|
||||
.map(Requirement::from_pep508)
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(Box::new)?;
|
||||
.collect::<Result<_, _>>()?;
|
||||
let constraints = PubGrubDependencies::from_requirements(
|
||||
&requirements,
|
||||
&self.constraints,
|
||||
|
@ -1008,8 +1007,7 @@ impl<
|
|||
.iter()
|
||||
.cloned()
|
||||
.map(Requirement::from_pep508)
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(Box::new)?;
|
||||
.collect::<Result<_, _>>()?;
|
||||
let constraints = PubGrubDependencies::from_requirements(
|
||||
&requirements,
|
||||
&self.constraints,
|
||||
|
|
|
@ -385,10 +385,10 @@ pub(crate) async fn pip_compile(
|
|||
.iter()
|
||||
.cloned()
|
||||
.map(Requirement::from_pep508)
|
||||
.collect::<Result<_, ParsedUrlError>>()?,
|
||||
.collect::<Result<_, _>>()?,
|
||||
optional_dependencies: IndexMap::default(),
|
||||
};
|
||||
Ok::<_, ParsedUrlError>((
|
||||
Ok::<_, Box<ParsedUrlError>>((
|
||||
built_editable.editable,
|
||||
built_editable.metadata,
|
||||
requirements,
|
||||
|
|
|
@ -694,7 +694,7 @@ async fn resolve(
|
|||
.cloned()
|
||||
.map(Requirement::from_pep508)
|
||||
.collect::<Result<_, _>>()?;
|
||||
Ok::<_, ParsedUrlError>((
|
||||
Ok::<_, Box<ParsedUrlError>>((
|
||||
built_editable.editable.clone(),
|
||||
built_editable.metadata.clone(),
|
||||
Requirements {
|
||||
|
@ -704,7 +704,7 @@ async fn resolve(
|
|||
))
|
||||
})
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(|err| Error::ParsedUrl(Box::new(err)))?;
|
||||
.map_err(Error::ParsedUrl)?;
|
||||
|
||||
// Determine any lookahead requirements.
|
||||
let lookaheads = match options.dependency_mode {
|
||||
|
|
|
@ -5224,7 +5224,7 @@ fn unsupported_scheme() -> Result<()> {
|
|||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Unsupported URL prefix `bzr` in URL: `bzr+https://example.com/anyio`
|
||||
error: Unsupported URL prefix `bzr` in URL: `bzr+https://example.com/anyio` (Bazaar is not supported)
|
||||
"###
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue