diff --git a/src-tauri/src/core/manager/state.rs b/src-tauri/src/core/manager/state.rs index db2bcae5e..acea6e44a 100644 --- a/src-tauri/src/core/manager/state.rs +++ b/src-tauri/src/core/manager/state.rs @@ -111,7 +111,11 @@ impl CoreManager { #[cfg(unix)] let previous_mask = unsafe { tauri_plugin_clash_verge_sysinfo::libc::umask(0o077) }; - let command = app_handle.shell().sidecar(clash_core.as_str())?.args([ + let command = app_handle + .shell() + .sidecar(clash_core.as_str()) + .map_err(|error| anyhow::anyhow!("failed to build sidecar command for core {clash_core:?}: {error:#}"))?; + let command = command.args([ "-d", dirs::path_to_str(&config_dir)?, "-f", @@ -128,7 +132,13 @@ impl CoreManager { "LISTEN_NAMEDPIPE_SDDL", crate::core::owner_identity::current_user_pipe_sddl()?, ); - let (mut rx, child) = command.spawn()?; + let (mut rx, child) = command.spawn().map_err(|error| { + anyhow::anyhow!( + "failed to start sidecar core {clash_core:?} with config {} and data directory {}: {error:#}", + config_file.display(), + config_dir.display() + ) + })?; #[cfg(target_os = "windows")] let job = { match create_and_assign_sidecar_job(child.pid()) { diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 79e83a4e2..756a4f2ae 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -438,7 +438,13 @@ fn macos_service_tool_path(source: &Path) -> Result { } fn service_core_path(clash_core: &str, bin_ext: &str) -> Result { - let sibling = current_exe()?.with_file_name(format!("{clash_core}{bin_ext}")); + let sibling = current_exe() + .map_err(|error| { + anyhow::anyhow!( + "failed to locate the current executable while resolving Service core {clash_core:?}: {error}" + ) + })? + .with_file_name(format!("{clash_core}{bin_ext}")); #[cfg(all(target_os = "macos", feature = "verge-dev"))] { @@ -898,7 +904,10 @@ pub(super) async fn start_with_existing_service(config_file: &Path) -> Result<() let err_msg = response.message; logging!(error, Type::Service, "启动核心失败: {}", err_msg); start_owner_monitor(); - bail!(err_msg); + bail!( + "failed to start Service core at {}: {err_msg}", + request.runtime.core_path + ); } let result = response.data.context("Clash Verge Service 未返回会话信息")?; diff --git a/src-tauri/src/core/validate.rs b/src-tauri/src/core/validate.rs index 55d62ec92..8afb25b69 100644 --- a/src-tauri/src/core/validate.rs +++ b/src-tauri/src/core/validate.rs @@ -348,12 +348,16 @@ impl CoreConfigValidator { logging!(info, Type::Validate, "验证目录: {}", app_dir_str); // 使用子进程运行clash验证配置 - let command = - app_handle - .shell() - .sidecar(clash_core.as_str())? - .args(["-t", "-d", app_dir_str, "-f", config_path]); - let output = command.output().await?; + let command = app_handle.shell().sidecar(clash_core.as_str()).map_err(|error| { + anyhow::anyhow!("failed to build validation command for core {clash_core:?}: {error:#}") + })?; + let command = command.args(["-t", "-d", app_dir_str, "-f", config_path]); + let output = command.output().await.map_err(|error| { + anyhow::anyhow!( + "failed to run validation core {clash_core:?} for config {config_path:?} in data directory {}: {error:#}", + app_dir.display() + ) + })?; let status = &output.status; let stderr = &output.stderr; diff --git a/src-tauri/src/utils/help.rs b/src-tauri/src/utils/help.rs index 90e2eb17f..f4cf5df35 100644 --- a/src-tauri/src/utils/help.rs +++ b/src-tauri/src/utils/help.rs @@ -256,7 +256,12 @@ pub fn snapshot_path(original_path: &Path) -> Result { .ok_or_else(|| anyhow!("Invalid log path"))? .join("temp"); - std::fs::create_dir_all(&temp_dir)?; + std::fs::create_dir_all(&temp_dir).map_err(|error| { + anyhow!( + "failed to create log snapshot directory {}: {error}", + temp_dir.display() + ) + })?; let temp_path = temp_dir.join(format!( "{}_{}.log", @@ -264,7 +269,13 @@ pub fn snapshot_path(original_path: &Path) -> Result { chrono::Local::now().format("%Y-%m-%d_%H-%M-%S") )); - std::fs::copy(original_path, &temp_path)?; + std::fs::copy(original_path, &temp_path).map_err(|error| { + anyhow!( + "failed to copy log snapshot from {} to {}: {error}", + original_path.display(), + temp_path.display() + ) + })?; Ok(temp_path) }