保留资源替换冲突具体详情

已知冲突分类继续给出动作文案并附带脱敏对象详情
This commit is contained in:
kdletters
2026-10-06 14:38:15 +08:00
parent 2fb2d25a68
commit 2e0bc3aeb1
3 changed files with 54 additions and 11 deletions
@@ -261,31 +261,54 @@ export function resourceVersionReplacementErrorMessage(error: unknown): string {
0,
400,
);
const withDetail = (base: string, marker: string) => {
const markerIndex = message.indexOf(marker);
const detail =
markerIndex < 0
? ''
: message
.slice(markerIndex + marker.length)
.replace(/^[\s::;,;]+/u, '')
.trim();
return detail ? `${base}:${detail}` : base;
};
if (message.includes('project-revision-conflict')) {
return '项目已被其它操作改动,请重试替换';
return withDetail(
'项目已被其它操作改动,请重试替换',
'project-revision-conflict',
);
}
if (message.includes('project-identity-conflict')) {
return '项目身份不一致,请重新打开项目后再试';
return withDetail(
'项目身份不一致,请重新打开项目后再试',
'project-identity-conflict',
);
}
if (message.includes('resource-replacement-incompatible')) {
const reason = message.split(':').pop()?.trim();
return reason ? `替换素材不兼容:${reason}` : '替换素材不兼容';
}
if (message.includes('源项目版本不存在')) {
return '当前版本已不存在,请刷新项目后重试';
return withDetail('当前版本已不存在,请刷新项目后重试', '源项目版本不存在');
}
if (message.includes('源版本未绑定该素材')) {
return '该素材不在当前版本的绑定里,不能替换';
return withDetail(
'该素材不在当前版本的绑定里,不能替换',
'源版本未绑定该素材',
);
}
if (message.includes('项目资源不存在')) {
return '替换素材未登记或已被删除';
return withDetail('替换素材未登记或已被删除', '项目资源不存在');
}
if (message.includes('替换素材与源素材相同')) {
return '替换素材与源素材相同';
}
if (message.includes('不可修改、删除或重排')) {
// 版本记录写入边界的拒绝:直接替换只允许改一个版本的绑定,走到这里说明写入被守门挡下了。
return '替换被项目版本写入边界拒绝,请刷新项目后重试';
return withDetail(
'替换被项目版本写入边界拒绝,请刷新项目后重试',
'项目版本记录写入后不可修改、删除或重排',
);
}
if (message.includes('必须在客户端内执行')) {
return '替换素材需要在客户端内执行';
@@ -10,16 +10,36 @@
*/
import { visibleClientErrorMessage } from '../../services/errorReporting';
function withMappedDetail(base: string, message: string, marker: string) {
const markerIndex = message.indexOf(marker);
const detail =
markerIndex < 0
? ''
: message
.slice(markerIndex + marker.length)
.replace(/^[\s::;,;]+/u, '')
.trim();
return detail ? `${base}:${detail}` : base;
}
export function projectAssetCommandErrorMessage(
error: unknown,
fallback: string,
): string {
const message = visibleClientErrorMessage(error, fallback);
if (message.includes('project-revision-conflict')) {
return '项目已被其它操作改动,请刷新后重试';
return withMappedDetail(
'项目已被其它操作改动,请刷新后重试',
message,
'project-revision-conflict',
);
}
if (message.includes('project-identity-conflict')) {
return '项目身份不一致,请重新打开项目后再试';
return withMappedDetail(
'项目身份不一致,请重新打开项目后再试',
message,
'project-identity-conflict',
);
}
return message;
}
@@ -204,17 +204,17 @@ describe('资源替换的展示层口径', () => {
resourceVersionReplacementErrorMessage(
new Error('源项目版本不存在:initial-1'),
),
).toBe('当前版本已不存在,请刷新项目后重试');
).toBe('当前版本已不存在,请刷新项目后重试:initial-1');
expect(
resourceVersionReplacementErrorMessage(
new Error('源版本未绑定该素材:initial-1 · asset-1'),
),
).toBe('该素材不在当前版本的绑定里,不能替换');
).toBe('该素材不在当前版本的绑定里,不能替换:initial-1 · asset-1');
expect(
resourceVersionReplacementErrorMessage(
new Error('项目资源不存在:asset-x'),
),
).toBe('替换素材未登记或已被删除');
).toBe('替换素材未登记或已被删除:asset-x');
expect(
resourceVersionReplacementErrorMessage(new Error('替换素材与源素材相同')),
).toBe('替换素材与源素材相同');