优化: R-PD-10 commands err_str helper 统一错误格式化(87 处)

mod.rs 加 pub fn err_str<E: ToString>,commands/ 10 文件 87 处 .map_err(|e| e.to_string()) → .map_err(err_str),残留 0(10 处复杂表达式 e 用于 format!/anyhow 保留)。行为零变化,统一入口为未来加日志/分类留点。批5,cargo workspace 0
This commit is contained in:
2026-06-15 05:45:04 +08:00
parent fddca9daf1
commit 892a642bd4
11 changed files with 105 additions and 94 deletions

View File

@@ -16,7 +16,7 @@ use df_workflow::executor::DagExecutor;
use crate::state::AppState;
use super::now_millis;
use super::{err_str, now_millis};
/// 转发到前端的事件载荷
#[derive(Debug, Clone, Serialize)]
@@ -41,11 +41,11 @@ pub async fn run_workflow(
config: serde_json::Value,
) -> Result<String, String> {
// 1. 先构建运行时 DAG校验失败直接返回不落库
let runtime_dag = state.registry.build_dag(&dag).map_err(|e| e.to_string())?;
let runtime_dag = state.registry.build_dag(&dag).map_err(err_str)?;
// 2. 写入执行记录status=running
let execution_id = new_id();
let dag_json = serde_json::to_string(&dag).map_err(|e| e.to_string())?;
let dag_json = serde_json::to_string(&dag).map_err(err_str)?;
let record = WorkflowRecord {
id: execution_id.clone(),
name,
@@ -61,7 +61,7 @@ pub async fn run_workflow(
.workflows
.insert(record)
.await
.map_err(|e| e.to_string())?;
.map_err(err_str)?;
// 3. 订阅事件总线,把事件转发给前端(收到完成/失败事件后退出)
let mut rx = state.event_bus.subscribe();
@@ -173,7 +173,7 @@ pub async fn run_workflow(
pub async fn list_workflow_executions(
state: State<'_, AppState>,
) -> Result<Vec<WorkflowRecord>, String> {
state.workflows.list_all().await.map_err(|e| e.to_string())
state.workflows.list_all().await.map_err(err_str)
}
/// 按 ID 查询工作流执行记录
@@ -186,7 +186,7 @@ pub async fn get_workflow_execution(
.workflows
.get_by_id(&id)
.await
.map_err(|e| e.to_string())
.map_err(err_str)
}
/// 发送人工审批响应