From 6f5b626a0d0042f24d6217044a2e5ecbd46410ad Mon Sep 17 00:00:00 2001 From: renoseven Date: Mon, 11 Aug 2025 16:45:24 +0800 Subject: [PATCH] syscare: add error log when external command exec failure Signed-off-by: renoseven --- syscare/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/syscare/src/main.rs b/syscare/src/main.rs index 7fde0ca..c636199 100644 --- a/syscare/src/main.rs +++ b/syscare/src/main.rs @@ -17,7 +17,7 @@ use std::{env, ffi::OsString, process}; use anyhow::{Context, Result}; use args::SubCommand; use flexi_logger::{LogSpecification, Logger, WriteMode}; -use log::{debug, LevelFilter}; +use log::{debug, error, LevelFilter}; use syscare_common::{concat_os, ffi::OsStrExt, os}; @@ -44,7 +44,20 @@ fn exec_external_cmd(mut args: Vec) -> ! { let exit_status = process::Command::new(&program).args(&args).status(); let exit_code = match exit_status { Ok(status) => status.code().unwrap_or(1), - Err(e) => e.raw_os_error().unwrap_or(1), + Err(e) => { + match e.kind() { + std::io::ErrorKind::NotFound => error!( + "Error: External command '{}' is not installed", + program.to_string_lossy() + ), + _ => error!( + "Error: Failed to execute '{}': {}", + program.to_string_lossy(), + e.to_string().to_lowercase() + ), + } + e.raw_os_error().unwrap_or(1) + } }; process::exit(exit_code); -- Gitee