refactor(logging): replace log_err! with structured logging_error! calls

refactor(cm-service): better error handling from Backend to Frontend
This commit is contained in:
Tunglies
2025-03-28 03:39:21 +08:00
parent 59caa22431
commit e8e16f7d57
18 changed files with 232 additions and 128 deletions

View File

@@ -5,34 +5,39 @@ use crate::{
utils::logging::Type,
};
async fn execute_service_operation(
service_op: impl std::future::Future<Output = Result<(), impl ToString + std::fmt::Debug>>,
op_type: &str,
) -> CmdResult {
if let Err(e) = service_op.await {
let emsg = format!("{} {} failed: {:?}", op_type, "service", e);
logging_error!(Type::Service, true, "{}", emsg);
return Err(emsg);
}
if let Err(e) = CoreManager::global().restart_core().await {
let emsg = format!("{} {} failed: {:?}", op_type, "core", e);
logging_error!(Type::Core, true, "{}", emsg);
return Err(emsg);
}
Ok(())
}
#[tauri::command]
pub async fn install_service() -> CmdResult {
logging_error!(Type::Service, true, service::install_service().await);
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
Ok(())
execute_service_operation(service::install_service(), "Install").await
}
#[tauri::command]
pub async fn uninstall_service() -> CmdResult {
logging_error!(Type::Service, true, service::uninstall_service().await);
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
Ok(())
execute_service_operation(service::uninstall_service(), "Uninstall").await
}
#[tauri::command]
pub async fn reinstall_service() -> CmdResult {
logging_error!(Type::Service, true, service::reinstall_service().await);
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
Ok(())
execute_service_operation(service::reinstall_service(), "Reinstall").await
}
#[tauri::command]
pub async fn repair_service() -> CmdResult {
logging_error!(
Type::Service,
true,
service::force_reinstall_service().await
);
logging_error!(Type::Core, true, CoreManager::global().restart_core().await);
Ok(())
execute_service_operation(service::force_reinstall_service(), "Repair").await
}