Add output_changed_message!, replace some .expects (#1110)

This commit is contained in:
Gideon
2025-04-13 10:43:08 +02:00
committed by GitHub
parent 801dddacd4
commit fd406f0f82
4 changed files with 37 additions and 26 deletions

View File

@@ -20,12 +20,12 @@ use crate::execution_context::ExecutionContext;
use crate::executor::ExecutorOutput;
use crate::terminal::{print_separator, shell};
use crate::utils::{check_is_python_2_or_shim, get_require_sudo_string, require, require_option, which, PathExt};
use crate::Step;
use crate::HOME_DIR;
use crate::{
error::{SkipStep, StepFailed, TopgradeError},
terminal::print_warning,
};
use crate::{output_changed_message, Step};
#[cfg(target_os = "linux")]
pub fn is_wsl() -> Result<bool> {
@@ -472,8 +472,9 @@ fn run_vscode_compatible<const VSCODIUM: bool>(ctx: &ExecutionContext) -> Result
Version::parse(&item).map_err(std::convert::Into::into)
}
None => {
return Err(eyre!(format!(
"The output of `{bin_name} --version` changed, please file an issue to Topgrade: No first line"
return Err(eyre!(output_changed_message!(
&format!("{bin_name} --version"),
"No first line"
)))
}
};
@@ -481,9 +482,8 @@ fn run_vscode_compatible<const VSCODIUM: bool>(ctx: &ExecutionContext) -> Result
// Raise any errors in parsing the version
// The benefit of handling VSCodium versions so old that the version format is something
// unexpected is outweighed by the benefit of failing fast on new breaking versions
let version = version.wrap_err(format!(
"the output of `{bin_name} --version` changed, please file an issue to Topgrade"
))?;
let version =
version.wrap_err_with(|| output_changed_message!(&format!("{bin_name} --version"), "Invalid version"))?;
debug!("Detected {name} version as: {version}");
if version < Version::new(1, 86, 0) {
@@ -674,9 +674,12 @@ pub fn run_pip3_update(ctx: &ExecutionContext) -> Result<()> {
{
Ok(output) => {
let stdout = output.stdout.trim();
stdout
.parse::<bool>()
.expect("unexpected output that is not `true` or `false`")
stdout.parse::<bool>().wrap_err_with(|| {
output_changed_message!(
"pip config get global.break-system-packages",
"unexpected output that is not `true` or `false`"
)
})?
}
// it can fail because this key may not be set
//
@@ -1344,7 +1347,7 @@ pub fn run_uv(ctx: &ExecutionContext) -> Result<()> {
// 2. "0.5.11+1"
};
let version =
Version::parse(version_str).expect("the output of `uv --version` changed, please file an issue to Topgrade");
Version::parse(version_str).wrap_err_with(|| output_changed_message!("uv --version", "Invalid version"))?;
if version < Version::new(0, 4, 25) {
// For uv before version 0.4.25 (exclusive), the `self` sub-command only