Add output_changed_message!, replace some .expects (#1110)
This commit is contained in:
@@ -3,7 +3,7 @@ use std::ffi::OsString;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::{Context, Result};
|
||||
use rust_i18n::t;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::error::TopgradeError;
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::utils::require_option;
|
||||
use crate::utils::which;
|
||||
use crate::{config, Step};
|
||||
use crate::{config, output_changed_message, Step};
|
||||
|
||||
fn get_execution_path() -> OsString {
|
||||
let mut path = OsString::from("/usr/bin:");
|
||||
@@ -285,7 +285,8 @@ impl ArchPackageManager for Aura {
|
||||
// Output will be something like: "aura x.x.x\n"
|
||||
let version_cmd_stdout = version_cmd_output.stdout;
|
||||
let version_str = version_cmd_stdout.trim_start_matches("aura ").trim_end();
|
||||
let version = Version::parse(version_str).expect("invalid version");
|
||||
let version = Version::parse(version_str)
|
||||
.wrap_err_with(|| output_changed_message!("aura --version", "invalid version"))?;
|
||||
|
||||
// Aura, since version 4.0.6, no longer needs sudo.
|
||||
//
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::process::Command;
|
||||
use std::{env::var, path::Path};
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::{Step, HOME_DIR};
|
||||
use crate::{output_changed_message, Step, HOME_DIR};
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
@@ -470,16 +470,10 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
||||
return Err(eyre!("`nix --version` output was empty"));
|
||||
}
|
||||
|
||||
let captures = NIX_VERSION_REGEX.captures(get_version_cmd_first_line_stdout);
|
||||
let raw_version = match &captures {
|
||||
None => {
|
||||
return Err(eyre!(
|
||||
"`nix --version` output was weird: {get_version_cmd_first_line_stdout:?}\n\
|
||||
If the `nix --version` output format changed, please file an issue to Topgrade"
|
||||
));
|
||||
}
|
||||
Some(captures) => &captures[1],
|
||||
};
|
||||
let captures = NIX_VERSION_REGEX
|
||||
.captures(get_version_cmd_first_line_stdout)
|
||||
.ok_or_else(|| eyre!(output_changed_message!("nix --version", "regex did not match")))?;
|
||||
let raw_version = &captures[1];
|
||||
|
||||
let version =
|
||||
Version::parse(raw_version).wrap_err_with(|| format!("Unable to parse Nix version: {raw_version:?}"))?;
|
||||
@@ -653,10 +647,11 @@ pub fn run_asdf(ctx: &ExecutionContext) -> Result<()> {
|
||||
let mut remaining = version_stdout.trim_start_matches('v');
|
||||
let idx = remaining
|
||||
.find('-')
|
||||
.expect("the output of `asdf version` changed, please file an issue to Topgrade");
|
||||
.ok_or_else(|| eyre!(output_changed_message!("asdf version", "no dash (-) found")))?;
|
||||
// remove the hash part
|
||||
remaining = &remaining[..idx];
|
||||
let version = Version::parse(remaining).expect("should be a valid version");
|
||||
let version =
|
||||
Version::parse(remaining).wrap_err_with(|| output_changed_message!("asdf version", "invalid version"))?;
|
||||
if version < Version::new(0, 15, 0) {
|
||||
ctx.run_type()
|
||||
.execute(&asdf)
|
||||
|
||||
Reference in New Issue
Block a user