Use a custom pubgrub report formatter (#521)

Uses https://github.com/zanieb/pubgrub/pull/10 to drastically simplify
our reporter implementation. This will allow us to make use of upstream
improvements to the reporter e.g.
https://github.com/zanieb/pubgrub/pull/8 without multiple duplicative
pull requests.
This commit is contained in:
Zanie Blue 2023-12-01 13:36:12 -06:00 committed by GitHub
parent efcc4f1409
commit 2a8544df9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 419 deletions

View file

@ -1,7 +1,7 @@
use std::fmt::Formatter;
use pubgrub::range::Range;
use pubgrub::report::Reporter;
use pubgrub::report::{DefaultStringReporter, Reporter};
use thiserror::Error;
use url::Url;
@ -11,7 +11,7 @@ use puffin_distribution::DistributionDatabaseError;
use puffin_normalize::PackageName;
use crate::pubgrub::{PubGrubPackage, PubGrubVersion};
use crate::ResolutionFailureReporter;
use crate::PubGrubReportFormatter;
#[derive(Error, Debug)]
pub enum ResolveError {
@ -78,7 +78,8 @@ 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);
let formatter = PubGrubReportFormatter;
let report = DefaultStringReporter::report_with_formatter(derivation_tree, &formatter);
write!(f, "{report}")
} else {
write!(f, "{}", self.source)