资源编辑错误通道补 typed 错误并把平台失败原文带出
- 新增 project/resource_editor/error.rs:ResourceEditError 只有 RemoteGenerationFailed { server_message } 与 Other(String) 两个变体,to_user_msg 是唯一写「资源编辑生成失败:…」的地方,Other 上留 // TODO refactor string-typed
- 轮询到 status=failed 时读平台 error 原文装进 RemoteGenerationFailed 带出,账本仍只写 terminal_failure_code,原文不进账本
- 删掉轮询与提交期 HTTP 400 两处首句失败文案的 remote-terminal-failed 前缀;ensure_resource_edit_phase_resumable 里的三个 token 保留
- 两个入口拆成 typed 实现与 Result<_, String> 外观:derive_local_project_resource_typed / resume_local_project_resource_edit_typed,旧名映射 to_user_msg 供既有调用点与 Tauri 命令使用
- 不提供 impl From<String>,每处 String 错误显式 .map_err(ResourceEditError::Other)
- terminal_failure_code 加 // TODO clean unnecessary 并写明清理前置条件(字段无 skip_serializing_if、账本带 deny_unknown_fields)
- 测试:远端终态断言平台原文进文案且不进账本,抠图远端失败改用 typed 入口覆盖无 error 时的兜底
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+9
-2
@@ -702,12 +702,19 @@ async fn background_removal_remote_failure_keeps_manifest_without_result() {
|
||||
|
||||
let error = with_test_credentials(
|
||||
&base_url,
|
||||
derive_local_project_resource_at(fixture.request.clone()),
|
||||
derive_local_project_resource_typed(fixture.request.clone()),
|
||||
)
|
||||
.await
|
||||
.expect_err("remote failure must be returned");
|
||||
server.join().expect("join failure server");
|
||||
assert!(error.contains("remote-terminal-failed"));
|
||||
// 平台没给 `error` 原文时走兜底文案(带原文的路径见 resource_editor.rs 的远端终态测试)。
|
||||
assert_eq!(
|
||||
error,
|
||||
ResourceEditError::RemoteGenerationFailed {
|
||||
server_message: None
|
||||
}
|
||||
);
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//! `resource_editor` 的错误定义。
|
||||
//!
|
||||
//! 这一层整体还是 `Result<_, String>`(见 `Other` 上的 TODO),这里先把**远端资源编辑终态
|
||||
//! 失败**这条穿出来:平台给的原因必须作为数据往上走,而不是在产生点就拼成一句带前缀的话——
|
||||
//! 否则工具层再也分不出「远端失败」和「本地失败」,只能把两句前缀叠在一起。
|
||||
|
||||
/// 资源编辑失败。
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum ResourceEditError {
|
||||
/// 平台轮询到终态 `status=failed`。`server_message` 是平台 `error` 字段原文,平台没给时为空。
|
||||
///
|
||||
/// 原文只进当次错误文案,不进账本(账本只存 `terminal_failure_code` 分类码)。
|
||||
RemoteGenerationFailed { server_message: Option<String> },
|
||||
/// 尚未分类的失败:`message` 是产生点写好的、可直接展示的文案或稳定码。
|
||||
// TODO refactor string-typed
|
||||
Other(String),
|
||||
}
|
||||
|
||||
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(),
|
||||
},
|
||||
Self::Other(message) => message.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ResourceEditError {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
formatter.write_str(&self.to_user_msg())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user