mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-29 03:02:55 +00:00
Surface invalid metadata as hints in error reports (#2850)
## Summary Closes #2847.
This commit is contained in:
parent
ee9059978a
commit
7ae06b3b46
7 changed files with 229 additions and 27 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt::Formatter;
|
||||
use std::ops::Deref;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ use crate::candidate_selector::CandidateSelector;
|
|||
use crate::dependency_provider::UvDependencyProvider;
|
||||
use crate::pubgrub::{PubGrubPackage, PubGrubPython, PubGrubReportFormatter};
|
||||
use crate::python_requirement::PythonRequirement;
|
||||
use crate::resolver::{UnavailablePackage, VersionsResponse};
|
||||
use crate::resolver::{IncompletePackage, UnavailablePackage, VersionsResponse};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum ResolveError {
|
||||
|
|
@ -125,6 +125,7 @@ impl From<pubgrub::error::PubGrubError<UvDependencyProvider>> for ResolveError {
|
|||
python_requirement: None,
|
||||
index_locations: None,
|
||||
unavailable_packages: FxHashMap::default(),
|
||||
incomplete_packages: FxHashMap::default(),
|
||||
})
|
||||
}
|
||||
pubgrub::error::PubGrubError::SelfDependency { package, version } => {
|
||||
|
|
@ -146,6 +147,7 @@ pub struct NoSolutionError {
|
|||
python_requirement: Option<PythonRequirement>,
|
||||
index_locations: Option<IndexLocations>,
|
||||
unavailable_packages: FxHashMap<PackageName, UnavailablePackage>,
|
||||
incomplete_packages: FxHashMap<PackageName, BTreeMap<Version, IncompletePackage>>,
|
||||
}
|
||||
|
||||
impl std::error::Error for NoSolutionError {}
|
||||
|
|
@ -167,6 +169,7 @@ impl std::fmt::Display for NoSolutionError {
|
|||
&self.selector,
|
||||
&self.index_locations,
|
||||
&self.unavailable_packages,
|
||||
&self.incomplete_packages,
|
||||
) {
|
||||
write!(f, "\n\n{hint}")?;
|
||||
}
|
||||
|
|
@ -261,6 +264,30 @@ impl NoSolutionError {
|
|||
self
|
||||
}
|
||||
|
||||
/// Update the incomplete packages attached to the error.
|
||||
#[must_use]
|
||||
pub(crate) fn with_incomplete_packages(
|
||||
mut self,
|
||||
incomplete_packages: &DashMap<PackageName, DashMap<Version, IncompletePackage>>,
|
||||
) -> Self {
|
||||
let mut new = FxHashMap::default();
|
||||
for package in self.derivation_tree.packages() {
|
||||
if let PubGrubPackage::Package(name, ..) = package {
|
||||
if let Some(entry) = incomplete_packages.get(name) {
|
||||
let versions = entry.value();
|
||||
for entry in versions {
|
||||
let (version, reason) = entry.pair();
|
||||
new.entry(name.clone())
|
||||
.or_insert_with(BTreeMap::default)
|
||||
.insert(version.clone(), reason.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.incomplete_packages = new;
|
||||
self
|
||||
}
|
||||
|
||||
/// Update the Python requirements attached to the error.
|
||||
#[must_use]
|
||||
pub(crate) fn with_python_requirement(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue