Skip to content

Commit

Permalink
Add context to unregistered task name to error context
Browse files Browse the repository at this point in the history
I caused this error during development and having the name of the task on it is helpful for debugging.
  • Loading branch information
konstin committed Jun 24, 2024
1 parent f073088 commit bb48d69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/uv-resolver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub enum ResolveError {
#[error(transparent)]
Join(#[from] tokio::task::JoinError),

#[error("Attempted to wait on an unregistered task")]
Unregistered,
#[error("Attempted to wait on an unregistered task: `{_0}`")]
UnregisteredTask(String),

#[error("Package metadata name `{metadata}` does not match given name `{given}`")]
NameMismatch {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolver/batch_prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl BatchPrefetcher {
let versions_response = index
.packages()
.wait_blocking(name)
.ok_or(ResolveError::Unregistered)?;
.ok_or_else(|| ResolveError::UnregisteredTask(name.to_string()))?;

let VersionsResponse::Found(ref version_map) = *versions_response else {
return Ok(());
Expand Down
15 changes: 8 additions & 7 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.index
.distributions()
.wait_blocking(&dist.version_id())
.ok_or(ResolveError::Unregistered)?;
.ok_or_else(|| ResolveError::UnregisteredTask(dist.version_id().to_string()))?;

// If we failed to fetch the metadata for a URL, we can't proceed.
let metadata = match &*response {
Expand Down Expand Up @@ -819,7 +819,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.index
.packages()
.wait_blocking(name)
.ok_or(ResolveError::Unregistered)?;
.ok_or_else(|| ResolveError::UnregisteredTask(name.to_string()))?;
visited.insert(name.clone());

let version_maps = match *versions_response {
Expand Down Expand Up @@ -991,13 +991,14 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
Some(url) => PubGrubDistribution::from_url(name, url),
None => PubGrubDistribution::from_registry(name, version),
};
let version_id = dist.version_id();

// Wait for the metadata to be available.
self.index
.distributions()
.wait_blocking(&version_id)
.ok_or(ResolveError::Unregistered)?;
.wait_blocking(&dist.version_id())
.ok_or_else(|| {
ResolveError::UnregisteredTask(dist.version_id().to_string())
})?;

return Ok(Dependencies::Available(Vec::default()));
}
Expand Down Expand Up @@ -1027,7 +1028,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.index
.distributions()
.wait_blocking(&version_id)
.ok_or(ResolveError::Unregistered)?;
.ok_or_else(|| ResolveError::UnregisteredTask(version_id.to_string()))?;

let metadata = match &*response {
MetadataResponse::Found(archive) => &archive.metadata,
Expand Down Expand Up @@ -1343,7 +1344,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
.packages()
.wait(&package_name)
.await
.ok_or(ResolveError::Unregistered)?;
.ok_or_else(|| ResolveError::UnregisteredTask(package_name.to_string()))?;

let version_map = match *versions_response {
VersionsResponse::Found(ref version_map) => version_map,
Expand Down

0 comments on commit bb48d69

Please sign in to comment.