Don't panic when cannot detect the arch package manager (fix #818)

This commit is contained in:
Roey Darwish Dror
2022-01-06 06:27:37 +02:00
parent fb0d726703
commit ff9072f7b1
2 changed files with 14 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
use std::process::ExitStatus;
use thiserror::Error;
#[derive(Error, Debug, PartialEq)]
@@ -16,6 +17,10 @@ pub enum TopgradeError {
#[error("Unknown Linux Distribution")]
#[cfg(target_os = "linux")]
UnknownLinuxDistribution,
#[error("Failed getting the system package manager")]
#[cfg(target_os = "linux")]
FailedGettingPackageManager,
}
#[derive(Error, Debug)]

View File

@@ -1,13 +1,16 @@
use crate::execution_context::ExecutionContext;
use crate::utils::which;
use crate::{config, Step};
use anyhow::Result;
use std::env::var_os;
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::process::Command;
use anyhow::Result;
use walkdir::WalkDir;
use crate::error::TopgradeError;
use crate::execution_context::ExecutionContext;
use crate::utils::which;
use crate::{config, Step};
fn get_execution_path() -> OsString {
let mut path = OsString::from("/usr/bin:");
path.push(var_os("PATH").unwrap());
@@ -171,7 +174,8 @@ pub fn get_arch_package_manager(ctx: &ExecutionContext) -> Option<Box<dyn ArchPa
}
pub fn upgrade_arch_linux(ctx: &ExecutionContext) -> Result<()> {
let package_manager = get_arch_package_manager(ctx).unwrap();
let package_manager =
get_arch_package_manager(ctx).ok_or_else(|| anyhow::Error::from(TopgradeError::FailedGettingPackageManager))?;
package_manager.upgrade(ctx)
}