mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-29 03:02:55 +00:00
Use a custom PubGrub error type to always show resolution report (#365)
Closes https://github.com/astral-sh/puffin/issues/356. The example from the issue now renders as: ``` ❯ cargo run --bin puffin-dev -q -- resolve-cli tensorflow-cpu-aws puffin-dev failed Caused by: No solution found when resolving build dependencies for source distribution: Caused by: Because there is no available version for tensorflow-cpu-aws and root depends on tensorflow-cpu-aws, version solving failed. ```
This commit is contained in:
parent
4eed03d8e7
commit
4fe583257e
5 changed files with 38 additions and 12 deletions
|
|
@ -1,4 +1,7 @@
|
|||
use std::fmt::Formatter;
|
||||
|
||||
use pubgrub::range::Range;
|
||||
use pubgrub::report::Reporter;
|
||||
use thiserror::Error;
|
||||
use url::Url;
|
||||
|
||||
|
|
@ -6,6 +9,7 @@ use pep508_rs::Requirement;
|
|||
use puffin_normalize::PackageName;
|
||||
|
||||
use crate::pubgrub::{PubGrubPackage, PubGrubVersion};
|
||||
use crate::ResolutionFailureReporter;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ResolveError {
|
||||
|
|
@ -25,7 +29,7 @@ pub enum ResolveError {
|
|||
Join(#[from] tokio::task::JoinError),
|
||||
|
||||
#[error(transparent)]
|
||||
PubGrub(#[from] pubgrub::error::PubGrubError<PubGrubPackage, Range<PubGrubVersion>>),
|
||||
PubGrub(#[from] RichPubGrubError),
|
||||
|
||||
#[error("Package metadata name `{metadata}` does not match given name `{given}`")]
|
||||
NameMismatch {
|
||||
|
|
@ -64,3 +68,28 @@ impl<T> From<futures::channel::mpsc::TrySendError<T>> for ResolveError {
|
|||
value.into_send_error().into()
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper around [`pubgrub::error::PubGrubError`] that displays a resolution failure report.
|
||||
#[derive(Debug)]
|
||||
pub struct RichPubGrubError {
|
||||
source: pubgrub::error::PubGrubError<PubGrubPackage, Range<PubGrubVersion>>,
|
||||
}
|
||||
|
||||
impl std::error::Error for RichPubGrubError {}
|
||||
|
||||
impl std::fmt::Display for RichPubGrubError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
if let pubgrub::error::PubGrubError::NoSolution(derivation_tree) = &self.source {
|
||||
let report = ResolutionFailureReporter::report(derivation_tree);
|
||||
write!(f, "{report}")
|
||||
} else {
|
||||
write!(f, "{}", self.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pubgrub::error::PubGrubError<PubGrubPackage, Range<PubGrubVersion>>> for ResolveError {
|
||||
fn from(value: pubgrub::error::PubGrubError<PubGrubPackage, Range<PubGrubVersion>>) -> Self {
|
||||
ResolveError::PubGrub(RichPubGrubError { source: value })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue