Show full error chain on tool upgrade failures (#8753)
Some checks are pending
CI / cargo clippy | ubuntu (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / lint (push) Waiting to run
CI / cargo clippy | windows (push) Blocked by required conditions
CI / cargo dev generate-all (push) Blocked by required conditions
CI / cargo shear (push) Waiting to run
CI / cargo test | ubuntu (push) Blocked by required conditions
CI / cargo test | macos (push) Blocked by required conditions
CI / test windows trampoline | x86_64 (push) Blocked by required conditions
CI / cargo test | windows (push) Blocked by required conditions
CI / check windows trampoline | aarch64 (push) Blocked by required conditions
CI / check windows trampoline | i686 (push) Blocked by required conditions
CI / check windows trampoline | x86_64 (push) Blocked by required conditions
CI / test windows trampoline | i686 (push) Blocked by required conditions
CI / typos (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / build binary | linux (push) Blocked by required conditions
CI / build binary | macos aarch64 (push) Blocked by required conditions
CI / build binary | macos x86_64 (push) Blocked by required conditions
CI / build binary | windows (push) Blocked by required conditions
CI / build binary | freebsd (push) Blocked by required conditions
CI / ecosystem test | prefecthq/prefect (push) Blocked by required conditions
CI / ecosystem test | pallets/flask (push) Blocked by required conditions
CI / integration test | conda on ubuntu (push) Blocked by required conditions
CI / integration test | free-threaded on linux (push) Blocked by required conditions
CI / integration test | free-threaded on windows (push) Blocked by required conditions
CI / integration test | pypy on ubuntu (push) Blocked by required conditions
CI / integration test | pypy on windows (push) Blocked by required conditions
CI / integration test | graalpy on ubuntu (push) Blocked by required conditions
CI / integration test | graalpy on windows (push) Blocked by required conditions
CI / integration test | github actions (push) Blocked by required conditions
CI / integration test | determine publish changes (push) Blocked by required conditions
CI / integration test | uv publish (push) Blocked by required conditions
CI / check cache | ubuntu (push) Blocked by required conditions
CI / check cache | macos aarch64 (push) Blocked by required conditions
CI / check system | python on debian (push) Blocked by required conditions
CI / check system | python on fedora (push) Blocked by required conditions
CI / check system | python on ubuntu (push) Blocked by required conditions
CI / check system | python on opensuse (push) Blocked by required conditions
CI / check system | python on rocky linux 8 (push) Blocked by required conditions
CI / check system | python on rocky linux 9 (push) Blocked by required conditions
CI / check system | pypy on ubuntu (push) Blocked by required conditions
CI / check system | pyston (push) Blocked by required conditions
CI / check system | alpine (push) Blocked by required conditions
CI / check system | python on macos aarch64 (push) Blocked by required conditions
CI / check system | homebrew python on macos aarch64 (push) Blocked by required conditions
CI / check system | python on macos x86_64 (push) Blocked by required conditions
CI / check system | python3.10 on windows (push) Blocked by required conditions
CI / check system | python3.10 on windows x86 (push) Blocked by required conditions
CI / check system | python3.13 on windows (push) Blocked by required conditions
CI / check system | python3.12 via chocolatey (push) Blocked by required conditions
CI / check system | python3.9 via pyenv (push) Blocked by required conditions
CI / check system | python3.13 (push) Blocked by required conditions
CI / check system | conda3.11 on linux (push) Blocked by required conditions
CI / check system | conda3.8 on linux (push) Blocked by required conditions
CI / check system | conda3.11 on macos (push) Blocked by required conditions
CI / check system | conda3.8 on macos (push) Blocked by required conditions
CI / check system | conda3.11 on windows (push) Blocked by required conditions
CI / check system | conda3.8 on windows (push) Blocked by required conditions
CI / check system | amazonlinux (push) Blocked by required conditions
CI / check system | embedded python3.10 on windows (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

As reported in https://github.com/astral-sh/uv/issues/8555
This commit is contained in:
Zanie Blue 2024-11-02 11:55:41 -05:00 committed by GitHub
parent d3e50a2376
commit 2ed94745a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 28 deletions

View file

@ -1,6 +1,7 @@
use std::{collections::BTreeSet, fmt::Write}; use std::{collections::BTreeSet, fmt::Write};
use anyhow::Result; use anyhow::Result;
use itertools::Itertools;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use tracing::debug; use tracing::debug;
@ -95,9 +96,7 @@ pub(crate) async fn upgrade(
// Determine whether we applied any upgrades. // Determine whether we applied any upgrades.
let mut did_upgrade_environment = vec![]; let mut did_upgrade_environment = vec![];
// Determine whether any tool upgrade failed. let mut errors = Vec::new();
let mut failed_upgrade = false;
for name in &names { for name in &names {
debug!("Upgrading tool: `{name}`"); debug!("Upgrading tool: `{name}`");
let result = upgrade_tool( let result = upgrade_tool(
@ -125,22 +124,31 @@ pub(crate) async fn upgrade(
debug!("Upgrading `{name}` was a no-op"); debug!("Upgrading `{name}` was a no-op");
} }
Err(err) => { Err(err) => {
// If we have a single tool, return the error directly. errors.push((name, err));
if names.len() > 1 {
writeln!(
printer.stderr(),
"Failed to upgrade `{}`: {err}",
name.cyan(),
)?;
} else {
writeln!(printer.stderr(), "{err}")?;
}
failed_upgrade = true;
} }
} }
} }
if failed_upgrade { if !errors.is_empty() {
for (name, err) in errors
.into_iter()
.sorted_unstable_by(|(name_a, _), (name_b, _)| name_a.cmp(name_b))
{
writeln!(
printer.stderr(),
"{}: Failed to upgrade {}",
"error".red().bold(),
name.green()
)?;
for err in err.chain() {
writeln!(
printer.stderr(),
" {}: {}",
"Caused by".red().bold(),
err.to_string().trim()
)?;
}
}
return Ok(ExitStatus::Failure); return Ok(ExitStatus::Failure);
} }

View file

@ -6,7 +6,7 @@ use uv_static::EnvVars;
use crate::common::{uv_snapshot, TestContext}; use crate::common::{uv_snapshot, TestContext};
#[test] #[test]
fn test_tool_upgrade_name() { fn tool_upgrade_name() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -56,7 +56,7 @@ fn test_tool_upgrade_name() {
} }
#[test] #[test]
fn test_tool_upgrade_multiple_names() { fn tool_upgrade_multiple_names() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -131,7 +131,7 @@ fn test_tool_upgrade_multiple_names() {
} }
#[test] #[test]
fn test_tool_upgrade_all() { fn tool_upgrade_all() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -205,7 +205,7 @@ fn test_tool_upgrade_all() {
} }
#[test] #[test]
fn test_tool_upgrade_non_existing_package() { fn tool_upgrade_non_existing_package() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -223,7 +223,8 @@ fn test_tool_upgrade_non_existing_package() {
----- stdout ----- ----- stdout -----
----- stderr ----- ----- stderr -----
`black` is not installed; run `uv tool install black` to install error: Failed to upgrade black
Caused by: `black` is not installed; run `uv tool install black` to install
"###); "###);
// Attempt to upgrade all. // Attempt to upgrade all.
@ -242,7 +243,7 @@ fn test_tool_upgrade_non_existing_package() {
} }
#[test] #[test]
fn test_tool_upgrade_not_stop_if_upgrade_fails() -> anyhow::Result<()> { fn tool_upgrade_not_stop_if_upgrade_fails() -> anyhow::Result<()> {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -314,14 +315,15 @@ fn test_tool_upgrade_not_stop_if_upgrade_fails() -> anyhow::Result<()> {
+ babel==2.14.0 + babel==2.14.0
- pytz==2018.5 - pytz==2018.5
Installed 1 executable: pybabel Installed 1 executable: pybabel
Failed to upgrade `python-dotenv`: `python-dotenv` is missing a valid receipt; run `uv tool install --force python-dotenv` to reinstall error: Failed to upgrade python-dotenv
Caused by: `python-dotenv` is missing a valid receipt; run `uv tool install --force python-dotenv` to reinstall
"###); "###);
Ok(()) Ok(())
} }
#[test] #[test]
fn test_tool_upgrade_settings() { fn tool_upgrade_settings() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -386,7 +388,7 @@ fn test_tool_upgrade_settings() {
} }
#[test] #[test]
fn test_tool_upgrade_respect_constraints() { fn tool_upgrade_respect_constraints() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -437,7 +439,7 @@ fn test_tool_upgrade_respect_constraints() {
} }
#[test] #[test]
fn test_tool_upgrade_constraint() { fn tool_upgrade_constraint() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -530,7 +532,7 @@ fn test_tool_upgrade_constraint() {
/// Upgrade a tool, but only by upgrading one of it's `--with` dependencies, and not the tool /// Upgrade a tool, but only by upgrading one of it's `--with` dependencies, and not the tool
/// itself. /// itself.
#[test] #[test]
fn test_tool_upgrade_with() { fn tool_upgrade_with() {
let context = TestContext::new("3.12") let context = TestContext::new("3.12")
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -578,7 +580,7 @@ fn test_tool_upgrade_with() {
} }
#[test] #[test]
fn test_tool_upgrade_python() { fn tool_upgrade_python() {
let context = TestContext::new_with_versions(&["3.11", "3.12"]) let context = TestContext::new_with_versions(&["3.11", "3.12"])
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();
@ -639,7 +641,7 @@ fn test_tool_upgrade_python() {
} }
#[test] #[test]
fn test_tool_upgrade_python_with_all() { fn tool_upgrade_python_with_all() {
let context = TestContext::new_with_versions(&["3.11", "3.12"]) let context = TestContext::new_with_versions(&["3.11", "3.12"])
.with_filtered_counts() .with_filtered_counts()
.with_filtered_exe_suffix(); .with_filtered_exe_suffix();