优化: 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:
@@ -8,7 +8,7 @@ use df_storage::models::TaskRecord;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
use super::now_millis;
|
||||
use super::{err_str, now_millis};
|
||||
|
||||
/// 创建任务入参
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -37,7 +37,7 @@ pub async fn list_tasks(
|
||||
Some(pid) => state.tasks.query("project_id", &pid).await,
|
||||
None => state.tasks.list_all().await,
|
||||
};
|
||||
result.map_err(|e| e.to_string())
|
||||
result.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 按 id 查任务,找不到返回 Err(供前端详情页)
|
||||
@@ -50,7 +50,7 @@ pub async fn get_task_by_id(
|
||||
.tasks
|
||||
.get_by_id(&id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.map_err(err_str)?
|
||||
.ok_or_else(|| format!("任务 {} 不存在", id))
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ pub async fn create_task(
|
||||
.tasks
|
||||
.insert(record.clone())
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(err_str)?;
|
||||
Ok(record)
|
||||
}
|
||||
|
||||
@@ -104,11 +104,11 @@ pub async fn update_task(
|
||||
.tasks
|
||||
.update_field(&id, &field, &value)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 删除任务
|
||||
#[tauri::command]
|
||||
pub async fn delete_task(state: State<'_, AppState>, id: String) -> Result<bool, String> {
|
||||
state.tasks.delete(&id).await.map_err(|e| e.to_string())
|
||||
state.tasks.delete(&id).await.map_err(err_str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user