More error context

This commit is contained in:
konstin 2025-05-08 15:43:03 +02:00
parent c309d3351c
commit 9717fb58af
5 changed files with 23 additions and 15 deletions

View file

@ -3,10 +3,10 @@ use std::fmt::Write;
use std::path::PathBuf;
use std::sync::Arc;
use anyhow::anyhow_original::Context;
use itertools::Itertools;
use owo_colors::OwoColorize;
use tracing::{debug, enabled, Level};
use uv_cache::Cache;
use uv_client::{BaseClientBuilder, FlatIndexClient, RegistryClientBuilder};
use uv_configuration::{
@ -437,7 +437,8 @@ pub(crate) async fn pip_install(
let install_path = std::path::absolute(&pylock)?;
let install_path = install_path.parent().unwrap();
let content = fs_err::tokio::read_to_string(&pylock).await?;
let lock = toml::from_str::<PylockToml>(&content)?;
let lock = toml::from_str::<PylockToml>(&content)
.with_context(|| format!("Not a valid pylock.toml file: {}", pylock.user_display()))?;
let resolution =
lock.to_resolution(install_path, marker_env.markers(), &tags, &build_options)?;

View file

@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Write;
use std::sync::Arc;
use anyhow::Result;
use anyhow::{Context, Result};
use owo_colors::OwoColorize;
use tracing::debug;
@ -372,7 +372,8 @@ pub(crate) async fn pip_sync(
let install_path = std::path::absolute(&pylock)?;
let install_path = install_path.parent().unwrap();
let content = fs_err::tokio::read_to_string(&pylock).await?;
let lock = toml::from_str::<PylockToml>(&content)?;
let lock = toml::from_str::<PylockToml>(&content)
.with_context(|| format!("Not a valid pylock.toml file: {}", pylock.user_display()))?;
let resolution =
lock.to_resolution(install_path, marker_env.markers(), &tags, &build_options)?;

View file

@ -236,10 +236,12 @@ async fn init_script(
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => None,
Err(err) => {
return Err(anyhow::Error::from(err).context(format!(
"Failed to read script at `{}`",
script_path.simplified_display().cyan()
)));
return Err(err).with_context(|| {
format!(
"Failed to read script at `{}`",
script_path.simplified_display().cyan()
)
});
}
};
@ -328,10 +330,12 @@ async fn init_project(
warn!("Ignoring workspace discovery error due to `--no-workspace`: {err}");
None
} else {
return Err(anyhow::Error::from(err).context(format!(
"Failed to discover parent workspace; use `{}` to ignore",
"uv init --no-workspace".green()
)));
return Err(err).with_context(|| {
format!(
"Failed to discover parent workspace; use `{}` to ignore",
"uv init --no-workspace".green()
)
});
}
}
}

View file

@ -1,4 +1,5 @@
use crate::commands::ExitStatus;
use anyhow::anyhow_original::Context;
use tokio::process::Child;
use tracing::debug;
@ -85,7 +86,7 @@ pub(crate) async fn run_to_completion(mut handle: Child) -> anyhow::Result<ExitS
}
// Get the parent PGID
let parent_pgid = getpgid(None)?;
let parent_pgid = getpgid(None).context("Failed to get current PID")?;
if let Some(child_pid) = *ChildPid::from(&handle) {
debug!("Spawned child {child_pid} in process group {parent_pgid}");
}
@ -147,7 +148,7 @@ pub(crate) async fn run_to_completion(mut handle: Child) -> anyhow::Result<ExitS
};
// Check if the child pgid has changed
let child_pgid = getpgid(Some(child_pid))?;
let child_pgid = getpgid(Some(child_pid)).context("Failed to get PID of child process")?;
// Increment the number of interrupts seen
sigint_count += 1;

View file

@ -357,7 +357,8 @@ pub(crate) async fn run(
.iter()
.flat_map(std::env::split_paths),
),
)?;
)
.context("Failed to build new PATH variable")?;
process.env(EnvVars::PATH, new_path);
// Spawn and wait for completion