From 7a5357e2b1048a93fe24db0c81fb26d6fd449a54 Mon Sep 17 00:00:00 2001 From: iff Date: Wed, 11 Dec 2024 22:35:11 +0100 Subject: [PATCH] fix: possible panic --- core/src/modes.rs | 2 +- core/src/system.rs | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/core/src/modes.rs b/core/src/modes.rs index 6bb31c3..8c82ebe 100644 --- a/core/src/modes.rs +++ b/core/src/modes.rs @@ -127,7 +127,7 @@ pub fn cnf(data: &mut Data) { let packages = match system::get_packages(data, &package_manager, executable) { Some(packages) => packages, None => { - eprintln!("{}: {}", "pay-respects".red(), t!("package-not-found")); + eprintln!("{} {}", "pay-respects:".red(), t!("package-not-found")); return; } }; diff --git a/core/src/system.rs b/core/src/system.rs index cf8c8e4..d75b011 100644 --- a/core/src/system.rs +++ b/core/src/system.rs @@ -6,6 +6,9 @@ use std::process::Stdio; pub fn get_package_manager(data: &mut Data) -> Option { if let Ok(package_manager) = std::env::var("_PR_PACKAGE_MANAGER") { + if package_manager.is_empty() { + return None; + } return Some(package_manager); } @@ -32,8 +35,8 @@ pub fn get_packages( "apt" => { if !data.executables.contains(&"apt-file".to_string()) { eprintln!( - "{}: apt-file is required to find packages", - "pay-respects".yellow() + "{} apt-file is required to find packages", + "pay-respects:".yellow() ); return None; } @@ -76,8 +79,8 @@ pub fn get_packages( "emerge" => { if !data.executables.contains(&"e-file".to_string()) { eprintln!( - "{}: pfl is required to find packages", - "pay-respects".yellow() + "{} pfl is required to find packages", + "pay-respects:".yellow() ); return None; } @@ -100,8 +103,8 @@ pub fn get_packages( "nix" => { if !data.executables.contains(&"nix-locate".to_string()) { eprintln!( - "{}: nix-index is required to find packages", - "pay-respects".yellow() + "{} nix-index is required to find packages", + "pay-respects:".yellow() ); return None; } @@ -162,7 +165,10 @@ pub fn get_packages( } None } - false => unreachable!("Unsupported package manager"), + false => { + eprintln!("{} Unsupported package manager", ":pay-respects".yellow()); + return None; + }, }, } }