资源编辑 typed 错误只给事实,前缀交给使用方
- ResourceEditError::to_user_msg 不再拼「资源编辑生成失败」:远端终态只回平台 error 原文,平台没给时统一说「服务器未返回错误信息」 - 桌面命令面 derive/resume_local_project_resource 自己补「资源编辑生成失败:」前缀,桌面 UI 文案不变,前缀落在它真正的使用者这一层 - 单测:typed 错误断言原文逐字透传与缺省兜底;抠图远端失败测试同口径更新 - decision-log 追加「前缀归属」决策(工具面各用各的前缀、桌面面用资源编辑生成失败、叶子错误不写死总结),pitfalls 同步口径
This commit is contained in:
@@ -562,7 +562,9 @@ pub(crate) async fn derive_local_project_resource(
|
||||
) -> Result<DeriveLocalProjectResourceResult, String> {
|
||||
let root = Path::new(input.project_path.trim());
|
||||
enforce_project_permission_policy(root, "asset.register")?;
|
||||
derive_local_project_resource_at(input).await
|
||||
derive_local_project_resource_at(input)
|
||||
.await
|
||||
.map_err(resource_edit_command_error)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -580,7 +582,15 @@ pub(crate) async fn resume_local_project_resource_edit(
|
||||
) -> Result<DeriveLocalProjectResourceResult, String> {
|
||||
let root = Path::new(input.project_path.trim());
|
||||
enforce_project_permission_policy(root, "asset.register")?;
|
||||
resume_local_project_resource_edit_at(input).await
|
||||
resume_local_project_resource_edit_at(input)
|
||||
.await
|
||||
.map_err(resource_edit_command_error)
|
||||
}
|
||||
|
||||
/// 桌面命令面给自己的资源编辑失败加前缀:typed 错误只带平台原文(或「服务器未返回错误信息」),
|
||||
/// 前缀是使用者的事——工具面用的是各工具自己的前缀,这里是桌面命令。
|
||||
fn resource_edit_command_error(cause: String) -> String {
|
||||
format!("资源编辑生成失败:{cause}")
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
+1
-1
@@ -714,7 +714,7 @@ async fn background_removal_remote_failure_keeps_manifest_without_result() {
|
||||
server_message: None
|
||||
}
|
||||
);
|
||||
assert_eq!(error.to_user_msg(), "资源编辑生成失败");
|
||||
assert_eq!(error.to_user_msg(), "服务器未返回错误信息");
|
||||
let manifest =
|
||||
read_existing_manifest_for_project(fixture.root()).expect("read unchanged manifest");
|
||||
assert_eq!(manifest.assets.len(), 1);
|
||||
|
||||
@@ -17,13 +17,16 @@ pub(crate) enum ResourceEditError {
|
||||
}
|
||||
|
||||
impl ResourceEditError {
|
||||
/// 面向用户与模型的文案。只有这一层知道「远端生成失败」该怎么说,
|
||||
/// 上层(工具层)原样透传,不再叠自己的前缀。
|
||||
/// 面向用户与模型的文案。
|
||||
///
|
||||
/// 这里只给事实:平台原文,或平台没给时的「服务器未返回错误信息」。「谁失败了」这类前缀由使用者
|
||||
/// 自己加(工具面用各工具自己的前缀,桌面命令面用「资源编辑生成失败」),这一层不替它们定调——
|
||||
/// 前缀写死在这里,非工具侧的调用方就只能看到一句没有信息量的总结。
|
||||
pub(crate) fn to_user_msg(&self) -> String {
|
||||
match self {
|
||||
Self::RemoteGenerationFailed { server_message } => match server_message {
|
||||
Some(server_message) => format!("资源编辑生成失败:{server_message}"),
|
||||
None => "资源编辑生成失败".to_string(),
|
||||
Some(server_message) => server_message.clone(),
|
||||
None => "服务器未返回错误信息".to_string(),
|
||||
},
|
||||
Self::Other(message) => message.clone(),
|
||||
}
|
||||
@@ -35,3 +38,26 @@ impl std::fmt::Display for ResourceEditError {
|
||||
formatter.write_str(&self.to_user_msg())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn remote_generation_failure_keeps_platform_text_verbatim() {
|
||||
let error = ResourceEditError::RemoteGenerationFailed {
|
||||
server_message: Some("provider detail".to_string()),
|
||||
};
|
||||
|
||||
assert_eq!(error.to_user_msg(), "provider detail");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_generation_failure_without_message_blames_the_server() {
|
||||
let error = ResourceEditError::RemoteGenerationFailed {
|
||||
server_message: None,
|
||||
};
|
||||
|
||||
assert_eq!(error.to_user_msg(), "服务器未返回错误信息");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user