优化: 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:
@@ -9,7 +9,7 @@ use df_storage::models::{IdeaRecord, ProjectRecord};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
use super::now_millis;
|
||||
use super::{err_str, now_millis};
|
||||
|
||||
/// 创建灵感入参
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -35,8 +35,8 @@ pub async fn list_ideas(
|
||||
status: Option<String>,
|
||||
) -> Result<Vec<IdeaRecord>, String> {
|
||||
match status {
|
||||
Some(s) => state.ideas.query("status", &s).await.map_err(|e| e.to_string()),
|
||||
None => state.ideas.list_all().await.map_err(|e| e.to_string()),
|
||||
Some(s) => state.ideas.query("status", &s).await.map_err(err_str),
|
||||
None => state.ideas.list_all().await.map_err(err_str),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ pub async fn create_idea(
|
||||
.ideas
|
||||
.insert(record.clone())
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(err_str)?;
|
||||
Ok(record)
|
||||
}
|
||||
|
||||
@@ -82,13 +82,13 @@ pub async fn update_idea(
|
||||
.ideas
|
||||
.update_field(&id, &field, &value)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 删除灵感
|
||||
#[tauri::command]
|
||||
pub async fn delete_idea(state: State<'_, AppState>, id: String) -> Result<bool, String> {
|
||||
state.ideas.delete(&id).await.map_err(|e| e.to_string())
|
||||
state.ideas.delete(&id).await.map_err(err_str)
|
||||
}
|
||||
|
||||
/// 将灵感晋升为项目 — 复用 df-project 领域逻辑创建项目,回写灵感 status=promoted/promoted_to
|
||||
@@ -101,7 +101,7 @@ pub async fn promote_idea(
|
||||
.ideas
|
||||
.get_by_id(&id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.map_err(err_str)?
|
||||
.ok_or_else(|| format!("灵感不存在: {id}"))?;
|
||||
|
||||
if record.promoted_to.is_some() {
|
||||
@@ -131,7 +131,7 @@ pub async fn promote_idea(
|
||||
.projects
|
||||
.insert(project_record)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(err_str)?;
|
||||
|
||||
// 回写灵感:status=promoted + promoted_to(update_full 单事务覆盖可变字段)
|
||||
// 补偿删除:第二步失败时回滚第一步已建的 project,保证最终一致性(非原子,但防项目存留而
|
||||
@@ -175,7 +175,7 @@ pub async fn evaluate_idea(
|
||||
.ideas
|
||||
.get_by_id(&id)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
.map_err(err_str)?
|
||||
.ok_or_else(|| format!("灵感不存在: {id}"))?;
|
||||
|
||||
let idea = record_to_idea(&record);
|
||||
@@ -186,7 +186,7 @@ pub async fn evaluate_idea(
|
||||
// 对抗式评估
|
||||
let eval = df_ideas::adversarial::AdversarialEngine::evaluate(&idea)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(err_str)?;
|
||||
|
||||
// 组装前端扁平结构(与 Ideas.vue 的 AdversarialEval interface 对齐)
|
||||
let positive_strength = eval.positive.confidence;
|
||||
@@ -243,7 +243,7 @@ pub async fn evaluate_idea(
|
||||
.ideas
|
||||
.update_full(&updated)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(err_str)?;
|
||||
|
||||
Ok(updated)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user