Merge pull request '统一用户报错为通俗中文提示' (#33) from codex/plain-language-errors into dev

This commit is contained in:
zhanghongming 2026-09-30 20:54:53 +08:00
commit 8824478498
60 changed files with 418 additions and 203 deletions

26
docs/ui/error-messages.md Normal file
View File

@ -0,0 +1,26 @@
# 用户可见报错文案
2026-09-30 用户确认:报错只用普通人能理解的话说明大概出了什么问题,不附技术解释或处理教程。重试、更新意见、查看提交结果等操作按钮仍保留。
## 规则
- 优先指出对象及问题,例如“账号或密码不正确”“视频时间范围加载失败”。
- 不在提示里展示接口名、字段路径、错误堆栈或英文异常。
- 区分确认失败与结果未知:连接中断或超时不能写成“保存失败”,使用“暂时无法确认操作结果”。
- 不推断责任:没有证据时不说是客户网络、账号被修改或数据丢失。
- 数据是否保留、是否已有部分成功属于必要事实,可以保留;不能凭空承诺。
- 表单缺项说明缺少什么,不笼统替换为“操作失败”。
## 实现边界
`src/lib/user-error-message.js` 只负责显示文本。公共 `getActionErrorMessage` 和页面报错展示调用此函数,覆盖认证、项目、账号、供应商、任务、切片、标注、质检、验收、工作流、文件存储、数据库、统计和预览等界面。审核保存、正式提交的提示同时更新。
保留 `APIError` 的原始 message、code、status、details、issues 和 requestId;认证判断、冲突检测、重试与结果核对继续使用原始对象。后端日志、算子日志、下载的诊断报告和客户填写的审核意见不做文案替换。未知技术报错使用对应操作的简短失败提示或“系统暂时无法完成操作”,不猜测具体原因。
新增报错须通过公共显示入口;新增稳定错误码应补充准确的中文分类。不能为修改提示而调整权限、保存、提交或恢复规则。
## 核验
类型检查、前端构建、通用错误映射及结果未知测试;前端全量测试与相同 HEAD 的独立基线逐项比较。页面测试使用本地拦截接口和虚构账号,不写客户数据。
本次核验结果:本地类型检查与构建通过;前端基线的14个失败用例及其断言原因与本次相同。使用本机 Edge 与虚构账号验证登录错误实际显示为“账号或密码不正确”,并验证审核冲突、视频错误和网络中断文案;所有业务接口由测试拦截。未连接公司集群或执行生产发布。

View File

@ -22,13 +22,13 @@ function RouteLoadError({ error }: { error?: Error | null }) {
return (
<div className="flex min-h-[360px] items-center justify-center p-6">
<div className="max-w-xl rounded-2xl border border-[#2a2b2f] bg-[#151619] p-6 text-center">
<div className="text-base font-semibold text-white">{isChunkError ? "页面资源已更新" : "页面遇到渲染异常"}</div>
<div className="text-base font-semibold text-white">{isChunkError ? "页面资源已更新" : "页面显示异常"}</div>
<p className="mt-2 text-sm leading-6 text-gray-400">
{isChunkError
? "当前页面加载的是旧版本资源,刷新后会重新载入最新页面。"
: error?.message || "组件渲染发生错误,请刷新重试。"}
: "页面暂时无法正常显示。"}
</p>
{!isChunkError && error?.stack ? (
{import.meta.env.DEV && !isChunkError && error?.stack ? (
<pre className="mt-3 max-h-40 overflow-auto rounded-lg bg-black/40 p-3 text-left font-mono text-xs text-rose-300">
{error.stack}
</pre>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState } from "react";
import { X, Sparkles, Loader2, AlertCircle } from "lucide-react";
import { generateWorkflowFromDescription, GeneratedWorkflow } from "../services/aiService";
@ -99,7 +100,7 @@ export default function AIGenerateModal({ isOpen, onClose, onGenerate }: AIGener
{error && (
<div className="p-3 bg-red-50 border border-red-200 rounded-lg flex items-center gap-3 text-red-700 text-xs dark:bg-red-500/10 dark:border-red-500/20 dark:text-red-300">
<AlertCircle className="w-4 h-4 shrink-0" />
{error}
{userErrorMessage(error)}
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useRef, useState } from "react";
import { Edit3, Loader2, Plus, Save, Trash2, X } from "lucide-react";
import { apiRequest } from "../services/api/client";
@ -227,7 +228,7 @@ export function AnnotationLabelsPanel({
{error && (
<div className="rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-200">
{error}
{userErrorMessage(error)}
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import type { ExecutionData } from "../types";
import { lazy, Suspense, useEffect, useState } from "react";
import { buildBrowserPlayableVideoURL, buildArtifactPlayableVideoURL } from "../lib/video-preview.js";
@ -186,7 +187,7 @@ function TextContentPreview({
<div className="rounded-lg border border-[#2a2b2f] bg-[#16181c] p-4 text-sm text-gray-400">正在加载预览...</div>
) : state.status === "error" ? (
<div className="rounded-lg border border-[#3f2424] bg-[#1f1111] p-4 text-sm text-red-200">
预览加载失败:{state.text}
预览加载失败:{userErrorMessage(state.text)}
</div>
) : (
<>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useRef, useState } from "react";
import { DeletionProgressBar } from "./DeletionProgressBar";
import { projectDeletionsApi, type DeletionPlan, type DeletionTask } from "../services/api/project-deletions";
@ -178,7 +179,7 @@ export function BatchProjectDeletionDialog({
</p>
{error && (
<p role="alert" className="break-words text-red-600">
{error}
{userErrorMessage(error)}
</p>
)}
{loading && <p role="status">正在核对全部项目的删除范围…</p>}
@ -229,7 +230,7 @@ export function BatchProjectDeletionDialog({
<p key={target.id} className="break-all py-1">
{target.status === "done" ? "✓" : "·"} {target.bucket ? `bos://${target.bucket}/` : ""}
{target.prefix || target.runId || "项目及关联业务记录"}
{target.error ? ` — ${target.error}` : ""}
{target.error ? ` — ${userErrorMessage(target.error)}` : ""}
</p>
))}
</details>
@ -247,7 +248,7 @@ export function BatchProjectDeletionDialog({
)}
{(row.error || row.task?.error) && (
<p role="alert" className="mt-2 break-words text-sm text-red-600">
{row.error || row.task?.error}
{userErrorMessage(row.error || row.task?.error)}
</p>
)}
{eligible(row) && (row.error || row.task?.retryable) && (

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { reviewShortcut, reviewShortcutHelp } from "../lib/review-shortcuts.js";
import type { ReviewViewingProps, ReviewViewingController, ReviewPosition, ReviewNavigation } from "./review-viewing";
import { ReviewVideoCaption, ReviewCaptionDetails, type ReviewCaption } from "./ReviewCaptions";
@ -2525,7 +2526,7 @@ export function CaptureAnnotationWorkbench({
>
<span>
{frameTimelineStatus === "error"
? "统一帧范围加载失败,已有内容已保留。请重试后再编辑。"
? "视频时间范围加载失败,已有内容已保留。"
: "正在加载统一帧范围…就绪前不能切分、逐帧、编辑或确认,可先播放预览。"}
</span>
{frameTimelineStatus === "error" && onRetryFrameTimeline && (
@ -2963,7 +2964,7 @@ export function CaptureAnnotationWorkbench({
)}
{transport.mediaError && (
<span role="alert" className="text-xs text-rose-300">
{transport.mediaError}{" "}
{userErrorMessage(transport.mediaError)}{" "}
<button
type="button"
className="underline"
@ -3089,7 +3090,7 @@ export function CaptureAnnotationWorkbench({
</div>
{phase === "slice" && error && !focusedLayout ? (
<p role="alert" className="mb-2 text-xs text-red-600">
{error}
{userErrorMessage(error)}
</p>
) : null}
<div
@ -3297,7 +3298,7 @@ export function CaptureAnnotationWorkbench({
value={selectedSlice.name || ""}
disabled={saving}
loading={sliceDictionaryLoading}
error={sliceDictionaryError}
error={userErrorMessage(sliceDictionaryError)}
onRefresh={onRefreshSliceDictionary}
onSelect={(name) => onSliceNameChange?.(selectedSlice.id, name)}
onCloseFocus={focusWorkbench}
@ -3320,7 +3321,7 @@ export function CaptureAnnotationWorkbench({
) : null}
{focusedLayout && error ? (
<p role="alert" className="capture-slice-error text-xs text-red-600">
{error}
{userErrorMessage(error)}
</p>
) : null}
</div>
@ -3416,7 +3417,7 @@ export function CaptureAnnotationWorkbench({
items={discardReasons}
allowManual={discardReasonsAllowManual}
loading={discardReasonsLoading}
error={discardReasonsError}
error={userErrorMessage(discardReasonsError)}
refresh={onRefreshDiscardReasons}
value={dispositionDraft}
onChange={(value) => setDispositionDraft((d) => ({ ...d, ...value }))}
@ -3424,7 +3425,7 @@ export function CaptureAnnotationWorkbench({
)}
{dispositionError && (
<p role="alert" className="capture-disposition-error mt-2 text-red-600">
{dispositionError}
{userErrorMessage(dispositionError)}
{dispositionError.includes("切片") && dispositionError.includes("名称") && (
<button type="button" className="mt-2 block underline" onClick={() => closeDisposition()}>
返回修正切片名称
@ -3584,7 +3585,7 @@ export function CaptureAnnotationWorkbench({
) : null}
{(!editingAnnotation || isQualityReview) && error ? (
<p role="alert" className="mb-2 text-xs text-red-600">
{error}
{userErrorMessage(error)}
</p>
) : null}
<div
@ -4423,7 +4424,7 @@ export function CaptureAnnotationWorkbench({
{error ? (
<p role="alert" className="mt-2 text-xs text-red-600">
{error}
{userErrorMessage(error)}
</p>
) : null}
<div className="capture-description-actions mt-3 flex flex-wrap items-center justify-between gap-2 border-t border-slate-200 pt-3 dark:border-[#2a2b2f]">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { WorkspaceDictionaryPanel } from "./WorkspaceDictionaryPanel";
import { useEffect, useRef, useState } from "react";
import type { AnnotationLabelRecord } from "../types";
@ -93,7 +94,7 @@ export function DiscardReasonFields({
searchLabel="搜索舍弃字典"
items={items.map((item) => ({ id: item.id, text: item.name }))}
value={selected?.name}
status={loading ? <p role="status">正在加载舍弃原因…</p> : error ? <p role="alert">{error}</p> : undefined}
status={loading ? <p role="status">正在加载舍弃原因…</p> : error ? <p role="alert">{userErrorMessage(error)}</p> : undefined}
onSelect={(id) => {
const item = items.find((item) => item.id === id);
if (item && !loading && !error) onChange({ ...value, reasonLabelId: item.id, reasonVersion: item.version });
@ -153,16 +154,16 @@ export function DiscardReasonFields({
<p role="status">正在加载舍弃原因…</p>
) : error ? (
<p role="alert" className="text-red-600">
{error}
{userErrorMessage(error)}
</p>
) : !items.length ? (
<p role="status">
{manual ? "当前项目未配置字典,请填写舍弃原因。" : "当前项目没有可用的舍弃原因,请联系管理员。"}
</p>
) : selected && selected.version !== value.reasonVersion ? (
<p role="alert">所选原因已更新,请重新选择并确认。</p>
<p role="alert">所选原因已更新。</p>
) : value.reasonLabelId && !selected ? (
<p role="alert">原选原因已不可用,请重新选择。</p>
<p role="alert">原选原因已不可用。</p>
) : null}
<button type="button" onClick={refresh} disabled={loading} className="text-sm text-blue-600 underline">
刷新原因字典

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { reviewShortcut } from "../lib/review-shortcuts.js";
import type { ReviewViewingProps, ReviewViewingController, ReviewPosition } from "./review-viewing";
import { ReviewCaptionDetails } from "./ReviewCaptions";
@ -581,7 +582,7 @@ export function FinalAcceptanceWorkspace({
</div>
) : loadError ? (
<div role="alert" className="m-4 rounded border border-red-300 p-3 text-sm text-red-600">
{loadError}
{userErrorMessage(loadError)}
</div>
) : !groups.length ? (
<p role="alert" className="p-4 text-sm text-amber-700">
@ -720,7 +721,7 @@ export function FinalAcceptanceWorkspace({
</p>
) : currentMetadata?.error ? (
<p role="alert" className="text-xs text-red-600">
{currentMetadata.error}
{userErrorMessage(currentMetadata.error)}
</p>
) : active.deliveryDisposition === "discard" ? (
<p className="text-xs text-slate-500">本片免标注;舍弃原因、视频及同步文件保留供审核。</p>
@ -977,7 +978,7 @@ export function FinalAcceptanceWorkspace({
)}
{error && (
<p role="alert" className="text-xs text-red-600">
{error}
{userErrorMessage(error)}
</p>
)}
</details>
@ -1048,7 +1049,7 @@ export function FinalAcceptanceWorkspace({
<p>正在加载…</p>
) : reviewsError ? (
<p role="alert" className="text-red-600">
{reviewsError}
{userErrorMessage(reviewsError)}
</p>
) : reviews.length ? (
reviews.map((review, index) => (

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { ExternalLink, PlayCircle } from "lucide-react";
import React from "react";
import { cn } from "../lib/utils";
@ -20,7 +21,7 @@ export function LazyVideoPreview({
className,
videoClassName,
errorTitle = "浏览器预览生成失败",
errorDescription = "系统已经尝试生成浏览器可播放的视频预览,但本次预览仍然失败。你仍可直接打开原始文件,或稍后重试。",
errorDescription = "视频预览加载失败。",
openOriginalLabel = "打开原始视频",
}: LazyVideoPreviewProps) {
const [activated, setActivated] = React.useState(false);
@ -41,7 +42,7 @@ export function LazyVideoPreview({
)}
>
<div className="font-medium">{errorTitle}</div>
<div className="mt-2 leading-6 text-amber-100/80">{errorDescription}</div>
<div className="mt-2 leading-6 text-amber-100/80">{userErrorMessage(errorDescription)}</div>
<a
href={fallbackURL}
target="_blank"

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { DragEvent, InputHTMLAttributes } from "react";
import {
@ -691,7 +692,7 @@ export function LightweightOperatorCodeEditor({
>
{lightweightFilesError ? (
<div className="rounded border border-red-500/20 bg-red-500/10 px-3 py-2 text-[11px] text-red-200">
{lightweightFilesError}
{userErrorMessage(lightweightFilesError)}
</div>
) : lightweightFilesLoading && !lightweightFiles ? (
<div className="flex items-center gap-2 px-2 py-3 text-xs text-gray-500">
@ -886,7 +887,7 @@ export function LightweightOperatorCodeEditor({
{lightweightFileError && (
<div className="border-b border-red-500/20 bg-red-500/10 px-4 py-2 text-xs text-red-200">
{lightweightFileError}
{userErrorMessage(lightweightFileError)}
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useMemo, useState } from "react";
import { Download, FolderOpen, Loader2, TriangleAlert } from "lucide-react";
import type { ExecutionData, RunArtifactManifestMember, RunArtifactManifestMembersResponse } from "../types";
@ -195,7 +196,7 @@ export function ManifestMemberBrowser({
if (state.status === "error") {
return (
<div className="rounded-lg border border-red-500/25 bg-red-500/10 p-4 text-xs text-red-200">
实际内容加载失败:{state.error}
实际内容加载失败:{userErrorMessage(state.error)}
</div>
);
}
@ -292,7 +293,7 @@ export function ManifestMemberBrowser({
加载更多内容
</button>
) : null}
{state.error ? <div className="text-[11px] text-amber-300">{state.error}</div> : null}
{state.error ? <div className="text-[11px] text-amber-300">{userErrorMessage(state.error)}</div> : null}
{selectedMember ? <MemberDetails member={selectedMember} /> : null}
{selectedMember?.contentAvailable && preview ? (
<ArtifactPreviewPanel item={preview} />

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { SyntheticEvent } from "react";
import {
@ -358,7 +359,7 @@ export function MaterializedSliceWorkbench({
);
}
if (error && sliceGroups.length === 0) {
return <div className="rounded-xl border border-red-500/30 bg-red-500/10 p-4 text-sm text-red-200">{error}</div>;
return <div className="rounded-xl border border-red-500/30 bg-red-500/10 p-4 text-sm text-red-200">{userErrorMessage(error)}</div>;
}
if (sliceGroups.length === 0) {
return (
@ -650,7 +651,7 @@ export function MaterializedSliceWorkbench({
</div>
) : metadataError ? (
<div className="rounded-lg border border-red-500/25 bg-red-500/10 p-3 text-xs text-red-200">
{metadataError}
{userErrorMessage(metadataError)}
</div>
) : actions.length ? (
<div className="max-h-64 space-y-2 overflow-auto pr-1">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import type { KeyboardEvent, PointerEvent, ReactNode } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import * as THREE from "three";
@ -310,7 +311,7 @@ export function ObjModelPreview({ src, title, actions, className, viewerClassNam
<span className="text-gray-300">正在加载 OBJ 预览...</span>
) : (
<span className="max-w-[520px] rounded-lg border border-[#3f2424] bg-[#1f1111] p-4 text-red-200">
OBJ 预览加载失败:{error || "未知错误"}
OBJ 预览加载失败:{userErrorMessage(error) || "模型暂时无法显示"}
</span>
)}
</div>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useState } from "react";
import { AlertTriangle, Blocks, CheckCircle2, Loader2, Save } from "lucide-react";
import { useUser } from "../context/UserContext";
@ -38,7 +39,7 @@ export default function PluginSettingsPanel() {
}, [role]);
if (!organization || !status) {
if (error || loadError) return <div className="text-sm text-red-700 dark:text-red-300">{error || loadError}</div>;
if (error || loadError) return <div className="text-sm text-red-700 dark:text-red-300">{userErrorMessage(error || loadError)}</div>;
return loading ? (
<div className="flex items-center gap-2 text-sm text-slate-600 dark:text-gray-400">
<Loader2 className="h-4 w-4 animate-spin" />
@ -227,7 +228,7 @@ export default function PluginSettingsPanel() {
</div>
) : null}
<div className="flex items-center justify-between border-t border-[color:var(--app-border)] px-6 py-3">
<span className="text-xs text-red-700 dark:text-red-300">{error}</span>
<span className="text-xs text-red-700 dark:text-red-300">{userErrorMessage(error)}</span>
<button
onClick={() => void save()}
disabled={saving}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React from "react";
import { AlertTriangle, CheckCircle2, ShieldCheck, XCircle } from "lucide-react";
import { summarizePocAcceptanceArtifact } from "../lib/poc-acceptance-summary.js";
@ -237,7 +238,7 @@ export function PocAcceptanceSummaryCard({ item }: { item: ExecutionData | Recor
{summary.failures.length > 0 && (
<ul className="mt-2 space-y-1">
{summary.failures.slice(0, 3).map((failure) => (
<li key={failure}>{failure}</li>
<li key={userErrorMessage(failure)}>{userErrorMessage(failure)}</li>
))}
</ul>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { productionDashboardApi, type ProductionResult } from "../services/api/production-dashboard";
@ -274,7 +275,7 @@ export function ProductionStatistics() {
)}
{error && (
<p role="alert" className="text-sm text-red-600">
{error}
{userErrorMessage(error)}
{result ? ",保留上次成功结果" : ",统计暂不可用"}
</p>
)}
@ -429,7 +430,7 @@ export function ProductionStatistics() {
/>
{detailError && (
<p role="alert" className="mt-4 text-red-600">
{detailError}
{userErrorMessage(detailError)}
</p>
)}
{!detail && !detailError ? <p className="py-4">加载中…</p> : null}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState } from "react";
import {
productionDashboardApi,
@ -49,7 +50,7 @@ export function ProductionStatisticsScope() {
</p>
{error && (
<p role="alert" className="text-sm text-red-600">
{error}{" "}
{userErrorMessage(error)}{" "}
<button onClick={() => void load()} className="underline">
重新加载
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useState } from "react";
import { DeletionProgressBar } from "./DeletionProgressBar";
import { projectDeletionsApi, type DeletionPlan, type DeletionTask } from "../services/api/project-deletions";
@ -30,14 +31,14 @@ export function ProjectDeletionDialog({projectId, taskId, onClose}: {key?:string
<section role="dialog" aria-modal="true" aria-label="级联删除项目" className="flex max-h-[90dvh] w-full max-w-3xl min-w-0 flex-col rounded-2xl border border-[color:var(--app-border)] bg-[color:var(--app-panel)] text-[color:var(--app-text)] shadow-2xl">
<header className="flex items-center justify-between border-b border-[color:var(--app-border)] p-5"><h2 className="font-bold">级联删除项目{plan? `:${plan.projectName}`:""}</h2><button aria-label="关闭删除详情" onClick={onClose}>关闭</button></header>
<div className="min-h-0 space-y-4 overflow-y-auto p-5">
{error&&<p role="alert" className="rounded border border-red-400 p-3 text-red-600">{error}</p>}
{error&&<p role="alert" className="rounded border border-red-400 p-3 text-red-600">{userErrorMessage(error)}</p>}
{!plan&&!error&&<p>正在核对删除范围…</p>}
{task&&<div role="status"><strong>{statuses[task.status]||task.status}</strong><p className="break-all text-sm">第 {task.attempt} 次执行 · {task.id}</p>{task.error&&<p className="text-red-600">{task.error}</p>}</div>}
{task&&<div role="status"><strong>{statuses[task.status]||task.status}</strong><p className="break-all text-sm">第 {task.attempt} 次执行 · {task.id}</p>{task.error&&<p className="text-red-600">{userErrorMessage(task.error)}</p>}</div>}
{plan&&<><p>仅删除本项目的业务记录、专属运行资源及生成产物。文件删除不可撤销,业务记录最后清理。</p>
<div className="flex flex-wrap gap-3">{Object.entries(plan.counts).map(([k,v])=><span key={k}>{labels[k]||k}:{v}</span>)}</div>
<div className="rounded border border-emerald-500/40 p-3 text-sm"><strong>保留内容</strong>{plan.preserved.map((x,i)=><p className="break-all" key={i}>{x}</p>)}</div>
{plan.blockers.map((x,i)=><p role="alert" className="text-red-600" key={i}>{x}</p>)}
<details open={Boolean(task)}><summary className="cursor-pointer">逐项清理清单({plan.targets.length} 项)</summary><ul className="mt-2 space-y-2">{plan.targets.map(t=><li className="break-all rounded border border-[color:var(--app-border)] p-2 text-sm" key={t.id}>{stages[t.kind]||t.kind} · {t.status==="done"?"已完成":t.status==="failed"?"失败":t.status==="running"?"执行中":"待执行"}<p>{t.bucket? `bos://${t.bucket}/`:""}{t.prefix||t.runId||"项目及关联业务记录"}</p>{t.error&&<p className="text-red-600">{t.error}</p>}</li>)}</ul></details>
<details open={Boolean(task)}><summary className="cursor-pointer">逐项清理清单({plan.targets.length} 项)</summary><ul className="mt-2 space-y-2">{plan.targets.map(t=><li className="break-all rounded border border-[color:var(--app-border)] p-2 text-sm" key={t.id}>{stages[t.kind]||t.kind} · {t.status==="done"?"已完成":t.status==="failed"?"失败":t.status==="running"?"执行中":"待执行"}<p>{t.bucket? `bos://${t.bucket}/`:""}{t.prefix||t.runId||"项目及关联业务记录"}</p>{t.error&&<p className="text-red-600">{userErrorMessage(t.error)}</p>}</li>)}</ul></details>
{canConfirm&&<div className="space-y-3"><label className="block">输入完整项目名称确认<input className="mt-1 w-full rounded border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-2" value={name} onChange={e=>setName(e.target.value)}/></label><label className="block">删除原因<input className="mt-1 w-full rounded border border-[color:var(--app-border)] bg-[color:var(--app-panel)] p-2" value={reason} onChange={e=>setReason(e.target.value)}/></label><label className="flex gap-2"><input type="checkbox" checked={stop} onChange={e=>setStop(e.target.checked)}/>允许停止本项目正在运行的任务(当前 {plan.blockingRunCount} 个)</label></div>}
</>}
</div>
@ -49,5 +50,5 @@ export function ProjectDeletionDialog({projectId, taskId, onClose}: {key?:string
export function ProjectDeletionHistory({onClose,onOpen}:{onClose:()=>void;onOpen:(id:string)=>void}) {
const [items,setItems]=useState<DeletionTask[]>([]);const [error,setError]=useState("");
useEffect(()=>{let active=true;void projectDeletionsApi.list().then(x=>{if(active)setItems(x)}).catch(e=>{if(active)setError(getActionErrorMessage(e,"读取失败"))});return()=>{active=false}},[]);
return <div className="fixed inset-0 z-[110] flex items-center justify-center bg-black/60 p-4"><section role="dialog" aria-modal="true" aria-label="删除记录" className="max-h-[85dvh] w-full max-w-2xl overflow-y-auto rounded-2xl bg-[color:var(--app-panel)] p-5 text-[color:var(--app-text)]"><header className="mb-4 flex justify-between"><h2>删除记录</h2><button onClick={onClose}>关闭</button></header>{error&&<p role="alert">{error}</p>}{!items.length&&!error&&<p>暂无删除记录</p>}{items.map(t=><button key={t.id} onClick={()=>onOpen(t.id)} className="mb-2 block w-full rounded border border-[color:var(--app-border)] p-3 text-left">{t.plan.projectName} · {statuses[t.status]||t.status}<p className="text-sm">{t.createdAt}</p></button>)}</section></div>
return <div className="fixed inset-0 z-[110] flex items-center justify-center bg-black/60 p-4"><section role="dialog" aria-modal="true" aria-label="删除记录" className="max-h-[85dvh] w-full max-w-2xl overflow-y-auto rounded-2xl bg-[color:var(--app-panel)] p-5 text-[color:var(--app-text)]"><header className="mb-4 flex justify-between"><h2>删除记录</h2><button onClick={onClose}>关闭</button></header>{error&&<p role="alert">{userErrorMessage(error)}</p>}{!items.length&&!error&&<p>暂无删除记录</p>}{items.map(t=><button key={t.id} onClick={()=>onOpen(t.id)} className="mb-2 block w-full rounded border border-[color:var(--app-border)] p-3 text-left">{t.plan.projectName} · {statuses[t.status]||t.status}<p className="text-sm">{t.createdAt}</p></button>)}</section></div>
}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useMemo, useRef, useState } from "react";
import { Check, Loader2, Search, Trash2, UserPlus, Users, RefreshCw } from "lucide-react";
import { usersApi } from "../services/api/users";
@ -255,7 +256,7 @@ export function ProjectMembersPanel({
</div>
{memberError ? (
<div role="alert" className="rounded-lg border border-red-500/30 px-4 py-3 text-sm text-red-600">
{memberError}
{userErrorMessage(memberError)}
<button type="button" onClick={() => void reload()} className="ml-3 underline">
重新加载成员
</button>
@ -263,7 +264,7 @@ export function ProjectMembersPanel({
) : null}
{error && !addOpen ? (
<div className="rounded-lg border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-200">
{error}
{userErrorMessage(error)}
</div>
) : null}
<div className="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm dark:border-[#2a2b2f] dark:bg-[#151619]">
@ -369,7 +370,7 @@ export function ProjectMembersPanel({
{loadingMembers || (loadedProjectId !== projectId && !memberError)
? "正在加载成员…"
: memberError
? "成员加载失败,请重试。"
? "成员加载失败。"
: members.length === 0
? "当前项目还没有成员。"
: "没有符合筛选条件的成员。"}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useState } from "react";
import { Box, CheckCircle2, Download, Loader2, TriangleAlert } from "lucide-react";
@ -66,7 +67,7 @@ export default function RerunArtifactPreview({ src, name }: { src: string; name:
) : (
<div className="flex items-start gap-2 text-amber-200">
<TriangleAlert className="mt-0.5 h-4 w-4" />
<span>Rerun 预览不可用:{state.message}。请使用原始视频或下载文件。</span>
<span>Rerun 预览不可用:{userErrorMessage(state.message)}。</span>
</div>
)}
</div>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useLayoutEffect, useRef } from "react";
import type { useReviewDraft } from "../hooks/useReviewDraft";
import type { ReviewProblem } from "../services/api/review-draft";
@ -35,7 +36,7 @@ export function ReviewProblemPanel({ review, label, navigationSliceId, writeLock
? "保存中"
: review.dirty
? "未保存"
: review.message || (review.draft ? "已保存" : "尚未加载")}
: userErrorMessage(review.message) || (review.draft ? "已保存" : "尚未加载")}
</span>
</div>
<div role="listbox" aria-label="审核意见范围" className="space-y-1">
@ -253,7 +254,7 @@ export function ReviewProblemPanel({ review, label, navigationSliceId, writeLock
))}
{review.error && (
<p role="alert" className="text-xs text-rose-600">
{review.error}
{userErrorMessage(review.error)}
<button
type="button"
disabled={review.saving}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useMemo, useState } from "react";
import {
Bug,
@ -194,7 +195,7 @@ export function RunArtifactsExplorer({
}
if (error) {
return <div className="rounded-xl border border-red-500/20 bg-red-50 p-4 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">{error}</div>;
return <div className="rounded-xl border border-red-500/20 bg-red-50 p-4 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">{userErrorMessage(error)}</div>;
}
if (!runId) {

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { usersApi } from "../services/api/users";
import React, { useEffect, useMemo, useState } from "react";
import { NavLink, useLocation } from "react-router-dom";
@ -418,7 +419,7 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
</div>
{profileError && (
<div className="rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-300">
{profileError}
{userErrorMessage(profileError)}
</div>
)}
</>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { BookOpen, Check, X } from "lucide-react";
@ -116,7 +117,7 @@ export function SliceNameDictionaryPicker({
<p role="status">正在加载切片字典…</p>
) : error ? (
<div role="alert">
{error}
{userErrorMessage(error)}
<button type="button" onClick={onRefresh}>
重试加载
</button>
@ -165,7 +166,7 @@ export function SliceNameDictionaryPicker({
</p>
) : error ? (
<div role="alert" className="p-2 text-xs text-amber-700">
{error}
{userErrorMessage(error)}
<button type="button" className="ml-2 underline" onClick={onRefresh}>
重试加载
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useState } from "react";
import { supplierAcceptanceApi, type SupplierAcceptanceAuthorization } from "../services/api/suppliers";
import { getActionErrorMessage } from "../lib/action-errors.js";
@ -82,7 +83,7 @@ export function SupplierAcceptancePanel({
{!canManage && <p className="text-sm text-slate-500">由平台管理员设置。</p>}
{error && (
<p role="alert" className="text-sm text-red-600">
{error}{" "}
{userErrorMessage(error)}{" "}
<button type="button" disabled={busy} className="underline" onClick={() => setAttempt((n) => n + 1)}>
刷新授权状态
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useCallback, useEffect, useRef, useState } from "react";
import { AlertCircle, Loader2, RefreshCw } from "lucide-react";
import { getActionErrorMessage } from "../lib/action-errors.js";
@ -185,12 +186,12 @@ export function SupplierAuthorizationsPanel({ supplierId, projectId, canManage }
</div>
{error && (
<p role="alert" className="text-sm text-red-600 dark:text-red-300">
{error}
{userErrorMessage(error)}
</p>
)}
{optionsError && (
<div role="alert" className="flex items-center gap-2 text-sm text-amber-700 dark:text-amber-300">
{optionsError}
{userErrorMessage(optionsError)}
<button type="button" disabled={busy} onClick={() => void load()} className="underline disabled:opacity-50">
重试
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useEffect, useState } from "react";
import { AlertCircle, Loader2, X } from "lucide-react";
import { getActionErrorMessage } from "../lib/action-errors.js";
@ -156,7 +157,7 @@ export function SupplierDeletionDialog({
)}
{error && (
<div role="alert" className="rounded-md border border-red-500/30 bg-red-500/10 p-3 text-sm text-red-600">
{error}
{userErrorMessage(error)}
{!loading && !plan && (
<button className="ml-3 underline" onClick={() => setReload((value) => value + 1)}>重试加载</button>
)}
@ -231,7 +232,7 @@ export function SupplierDeletionDialog({
</p>
{task.error && (
<p role="alert" className="text-red-600">
{task.error}
{userErrorMessage(task.error)}
</p>
)}
</div>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useMemo, useState } from "react";
import { AlertCircle, Loader2, Lock, LogIn, Phone, Shield, User } from "lucide-react";
import { useUser } from "../context/UserContext";
@ -84,7 +85,7 @@ export function UserBootstrapPanel() {
{(error || submitError) && (
<div className="flex items-start gap-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-200">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{submitError || error}</span>
<span>{userErrorMessage(submitError || error)}</span>
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useState } from "react";
import { Settings2, X } from "lucide-react";
import { workflowsApi } from "../services/api/workflows";
@ -102,7 +103,7 @@ export function WorkflowRunSettings({
<div className="space-y-4 overflow-y-auto p-4">
{error && (
<p role="alert" className="text-red-700 dark:text-red-300">
{error}{" "}
{userErrorMessage(error)}{" "}
<button onClick={() => void load()} disabled={busy} className="underline">
重新加载
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState } from "react";
import type { WorkforceStatistics, WorkforceReturnMetrics, WorkforceReturnDetail } from "../types";
import { workforceApi, type WorkforceDetailQuery } from "../services/api/workforce";
@ -68,7 +69,7 @@ function ReturnDetails({ query }: { query: WorkforceDetailQuery; key?: string })
<div className="mt-3 space-y-3">
{error ? (
<p role="alert">
{error}{" "}
{userErrorMessage(error)}{" "}
<button className="underline" onClick={() => setAttempt(attempt + 1)}>
重试
</button>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../../lib/user-error-message.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { AlertCircle, CheckCircle2, FolderUp, Loader2, Pause, Play, RefreshCw, Square, Upload } from "lucide-react";
import type { ObjectStorageUploadSessionItem, ObjectStorageUploadSessionSummary } from "../../types";
@ -556,7 +557,7 @@ export function DirectoryUploadPanel({
className={`flex items-center gap-2 rounded-xl border px-3 py-2 text-xs ${error ? "border-red-500/30 bg-red-500/10 text-red-200" : "border-emerald-500/30 bg-emerald-500/10 text-emerald-100"}`}
>
{error ? <AlertCircle className="h-4 w-4" /> : <CheckCircle2 className="h-4 w-4" />}
{error || message}
{userErrorMessage(error || message)}
</div>
) : null}
{knownSessions.length > 1 ? (
@ -586,7 +587,7 @@ export function DirectoryUploadPanel({
{item.relativePath}
</div>
<div className="mt-0.5 truncate font-mono text-[10px] text-gray-600">{item.key}</div>
{item.error ? <div className="mt-1 text-red-300">{item.error}</div> : null}
{item.error ? <div className="mt-1 text-red-300">{userErrorMessage(item.error)}</div> : null}
</div>
<div className="shrink-0 text-right">
<div className={itemTone[item.status] || "text-gray-300"}>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../../lib/user-error-message.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Check, ChevronLeft, File, Folder, Loader2, RefreshCw, Search, X } from "lucide-react";
import { getActionErrorMessage } from "../../lib/action-errors.js";
@ -346,7 +347,7 @@ export function ObjectStorageReferencePicker({
{errorMessage ? (
<div className="mt-3 rounded-lg border border-red-500/20 bg-red-500/10 px-3 py-2 text-xs text-red-700 dark:text-red-300">
{errorMessage}
{userErrorMessage(errorMessage)}
</div>
) : null}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../../lib/user-error-message.js";
import { useEffect, useMemo, useState } from "react";
import { Copy, KeyRound, Loader2, RotateCw, XCircle } from "lucide-react";
import { getActionErrorMessage } from "../../lib/action-errors.js";
@ -172,7 +173,7 @@ export function DrosyncCredentialPanel({ spaces, credentials, onChanged }: Drosy
{error ? (
<div className="mx-5 mt-5 rounded-lg border border-rose-500/20 bg-rose-500/10 px-3 py-2.5 text-xs text-rose-100">
{error}
{userErrorMessage(error)}
</div>
) : null}

View File

@ -3,9 +3,9 @@ import { APIError } from "../services/api/client";
import { reviewDecisionApi, type ReviewDecisionReceipt } from "../services/api/review-decision";
function failedDecisionMessage(error?: string) {
if (!error || error.includes("提交前校验未通过")) return "这次审核没有提交成功,已保存的问题还在。请检查后重新提交。";
if (error.includes("记录过大")) return "这条任务暂时无法提交,已保存的问题还在。请联系管理员处理。";
if (error.includes("记录保存失败")) return "这次审核没有提交成功,已保存的问题还在。请稍后重试。";
if (!error || error.includes("提交前校验未通过")) return "这次审核未提交成功,已保存的意见仍保留。";
if (error.includes("记录过大")) return "任务数据量过大,审核未能提交。";
if (error.includes("记录保存失败")) return "这次审核未提交成功,已保存的意见仍保留。";
return error;
}
@ -65,11 +65,11 @@ export function useReviewDecision(
const stored = JSON.parse(localStorage.getItem(storageKey) || "null") as PendingReviewDecision | null;
pendingRef.current = stored;
setPending(stored);
setMessage(stored ? "上次审核提交还没确认结果,请点击“查看提交结果”。" : "");
setMessage(stored ? "上次审核是否提交成功,暂时还不确定。" : "");
} catch {
pendingRef.current = null;
setPending(null);
setMessage("暂时找不到上次提交记录,请重新打开任务查看。");
setMessage("暂时找不到上次提交记录。");
}
return () => {
resolver.current?.(null);
@ -110,7 +110,7 @@ export function useReviewDecision(
resolver.current = null;
} else {
setFailureVersion((v) => v + 1);
setMessage("上次提交还在处理中,连续审查已暂停。请稍后点击“查看提交结果”。");
setMessage("上次提交还在处理中,连续审查已暂停。");
}
} catch (cause) {
if (key !== keyRef.current) return;
@ -119,10 +119,10 @@ export function useReviewDecision(
setCanRetry(missing);
setMessage(
missing
? "暂未查到上次提交。可点击“查看提交结果”,或“重试提交”。"
? "暂未查到上次提交的结果。"
: cause instanceof Error
? cause.message
: "暂时查不到提交结果,请稍后重试。",
: "暂时查不到提交结果。",
);
} finally {
if (key === keyRef.current) {
@ -143,7 +143,7 @@ export function useReviewDecision(
try {
if (beforeSendRef.current && !(await beforeSendRef.current(request))) {
if (key === keyRef.current) {
setMessage("连续审查状态已变化,未发送本次请求。请核对后重新确认。");
setMessage("连续审查已变化,本次审核尚未提交。");
resolver.current?.(null);
resolver.current = null;
}
@ -151,7 +151,7 @@ export function useReviewDecision(
}
if (key !== keyRef.current) return;
const headers = headersRef.current?.();
if (!headers) throw new Error("请重新打开刚才的任务,在可以编辑后重试提交。");
if (!headers) throw new Error("当前页面暂时不能提交审核。");
// Persist before dispatch. If storage fails, no formal request is issued.
writePending(request, key);
await reviewDecisionApi.send(request.path, { ...request.payload, operationId: request.operationId }, headers);
@ -160,12 +160,12 @@ export function useReviewDecision(
if (receipt.status === "completed") finish(request, receipt, key);
else {
setFailureVersion((v) => v + 1);
setMessage("提交正在处理,请点击“查看提交结果”。");
setMessage("审核正在提交,结果尚未确认。");
}
} catch (cause) {
if (key !== keyRef.current) return;
setFailureVersion((v) => v + 1);
setMessage(cause instanceof Error ? cause.message : "暂时无法确认是否提交成功,请点击“查看提交结果”。");
setMessage(cause instanceof Error ? cause.message : "暂时无法确认审核是否提交成功。");
// A transport failure is never evidence that the request had no effect.
if (cause instanceof APIError) {
try {

View File

@ -164,7 +164,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
const { draft } = await reviewDraftApi.get(itemId);
if (!valid()) return false;
if (draft.resultVersion !== m.draft?.resultVersion)
throw new Error("标注内容已更新,请重新打开任务。未保存文字仍保留。");
throw new Error("标注内容已更新,未保存文字仍保留。");
if (applied(draft, p)) {
settle(draft, p);
continue;
@ -178,7 +178,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
m.pending = null;
m.draft = draft;
m.blocked = true;
m.error = "上次保存未成功,文字仍保留。请检查后再保存。";
m.error = "上次保存未成功,文字仍保留。";
return false;
}
} catch (cause) {
@ -193,7 +193,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
const stored = opinionGroups(draft.problems).get(targetKey) || [];
if (groupSignature(stored) !== groupSignature(intent.editor.baseGroup)) {
m.blocked = true;
m.error = "这处意见已有更新,你的文字还在。请打开该意见检查后再保存。";
m.error = "这条审核意见已被修改,本次保存未成功。";
return false;
}
m.queue.delete(targetKey);
@ -217,7 +217,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
const readback = await reviewDraftApi.get(itemId);
if (!valid()) return false;
if (readback.draft.resultVersion !== saved.draft.resultVersion || !applied(readback.draft, p))
throw new Error("暂时无法确认是否保存成功,文字仍保留,请更新意见。");
throw new Error("暂时无法确认是否保存成功,文字仍保留。");
settle(readback.draft, p);
} catch (cause) {
if (!valid()) return false;
@ -244,8 +244,8 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
continue;
}
m.draft = draft;
m.error = "意见已更新,你的文字还在。请检查后再点保存。";
} else m.error = "标注内容已更新,你的文字还在,请重新打开任务。";
m.error = "这条审核意见已被修改,本次保存未成功。";
} else m.error = "标注内容已更新,未保存文字仍保留。";
} catch {
/* Preserve text and the recoverable error. */
}
@ -294,7 +294,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
m.selected = scope;
if (edit) {
if (!writable()) {
m.message = "当前页面不能编辑,请先取得编辑权。";
m.message = "当前页面暂时不能修改审核意见。";
notify();
return false;
}
@ -447,19 +447,19 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
const { draft } = await reviewDraftApi.get(itemId);
if (owner !== epoch.current || key !== contextRef.current) return;
if (draft.resultVersion !== sessionRef.current.snapshot?.resultVersion) {
m.error = "标注内容已更新,请重新打开任务。";
m.error = "标注内容已更新。";
return;
}
m.draft = draft;
if (m.pending && applied(draft, m.pending)) settle(draft, m.pending);
else if (m.pending) {
m.error = "暂时无法确认上次保存结果,请重试保存。文字仍保留。";
m.error = "暂时无法确认上次保存结果,文字仍保留。";
return;
}
m.error = "";
m.message = "意见已更新,未保存的文字仍保留。";
} catch (e) {
if (owner === epoch.current) m.error = e instanceof Error ? e.message : "加载失败,请更新意见。";
if (owner === epoch.current) m.error = e instanceof Error ? e.message : "审核意见加载失败。";
} finally {
if (owner === epoch.current) {
m.loading = false;
@ -486,7 +486,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
for (const [key, e] of m.edits) {
if (e.legacy) {
m.showSummary = true;
m.error = "有同一对象的多条旧意见,请逐项确认后保存。";
m.error = "同一位置有多条旧意见,最终意见尚未确认。";
notify();
return false;
}
@ -509,7 +509,7 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
if (!(await saveAll())) return false;
if ([...groups().values()].some((g) => g.length > 1)) {
m.showSummary = true;
m.error = "有同一对象的多条旧意见,请先确认最终意见再提交。";
m.error = "同一位置的旧意见尚未确认,审核未能提交。";
notify();
return false;
}
@ -593,14 +593,14 @@ export function useReviewDraft(itemId: string, userId: string, enabled: boolean,
.then(({ draft }) => {
if (owner !== epoch.current) return;
if (draft.resultVersion !== sessionRef.current.snapshot?.resultVersion) {
old.error = "标注内容已更新,请重新打开任务。";
old.error = "标注内容已更新。";
return;
}
old.draft = draft;
if (old.pending && applied(draft, old.pending)) settle(draft, old.pending);
})
.catch((e) => {
if (owner === epoch.current) old.error = e instanceof Error ? e.message : "加载失败,请更新意见。";
if (owner === epoch.current) old.error = e instanceof Error ? e.message : "审核意见加载失败。";
})
.finally(() => {
if (owner === epoch.current) {

View File

@ -1,18 +1,7 @@
import { userErrorMessage } from "./user-error-message.js";
export function getActionErrorMessage(error, fallback = "操作失败") {
if (error?.code === "version_conflict") {
return "任务版本已更新,本次操作未保存。请确认最新任务状态后重试;不会覆盖其他操作。";
}
const fallbackMessage = String(fallback || "").trim() || "操作失败";
if (error instanceof Error && error.message.trim()) {
return error.message.trim();
}
if (typeof error === "string" && error.trim()) {
return error.trim();
}
if (error && typeof error === "object" && typeof error.message === "string" && error.message.trim()) {
return error.message.trim();
}
return fallbackMessage;
return userErrorMessage(error, userErrorMessage(fallback) || "操作失败") || userErrorMessage(fallback) || "操作失败";
}
const RECOVERABLE_GATEWAY_STATUSES = new Set([502, 503, 504]);

View File

@ -0,0 +1,80 @@
/** Display-only wording. Never use this text to classify errors or change retry behaviour. */
export function userErrorMessage(value, fallback = "操作暂时未完成") {
if (value == null || value === "") return "";
const raw = typeof value === "string" ? value : value?.message || "";
const text = raw.trim();
const code = typeof value === "object" ? value?.code || "" : "";
const status = typeof value === "object" ? Number(value?.status) : 0;
const source = `${code} ${text}`;
const rules = [
[/HTTP\s*(502|503|504)|Bad Gateway|Service Unavailable|Gateway Timeout/i, "系统服务暂时不可用"],
[/kubernetes job|container.*(?:failed|terminated)|pod.*(?:failed|evicted)/i, "后台任务运行异常"],
[/Mongo(?:DB)?.*(?:error|failed)|database.*(?:connection|unavailable)/i, "系统数据暂时无法读取"],
[/请在视频画面就绪后记录意见/, "视频尚未加载完成,暂时不能记录意见"],
[/请先发布工作流/, "工作流尚未发布"],
[/请先到项目.*已授权供应商/, "项目尚未授权供应商"],
[/invalid (phone|email|username|account).*password|invalid credentials/i, "账号或密码不正确"],
[/API token is required|login is required|unauthenticated|authentication required/i, "登录信息缺失或已失效"],
[/csrf/i, "当前登录状态无法完成这次操作"],
[
/review_draft_version_conflict|已保存草稿已有新版本|这处意见已有更新|意见已更新.*再.*保存/,
"这条审核意见已被修改,本次保存未成功",
],
[/version_conflict|version mismatch/i, "内容已被修改,本次操作未完成"],
[/存在尚未核对的正式决定|上次审核提交还没确认结果/, "上次审核是否提交成功,暂时还不确定"],
[/提交前校验未通过/, "审核内容有不符合要求的地方,未能提交"],
[/被审结果已变化|标注内容已更新/, "这条任务的标注内容已更新"],
[/没有审查编辑权|未取得编辑权|没有编辑权/, "当前页面暂时不能修改审核意见"],
[/失去心跳|心跳.*超时|heartbeat.*(lost|timeout|expired)|lost heartbeat/i, "任务处理已中断"],
[/lease.*(expired|lost)|租约.*(失效|过期)/i, "当前页面的任务操作权限已失效"],
[/invalid.*presign|signature.*(expired|mismatch)|签名.*过期/i, "文件访问链接已失效"],
[/Failed to fetch|NetworkError|network request failed|Load failed|ERR_NETWORK/i, "连接中断,暂时无法确认操作结果"],
[/timeout|timed out|deadline exceeded/i, "系统响应超时,暂时无法确认操作结果"],
[/forbidden|permission denied|access denied|not authorized/i, "当前账号没有操作权限"],
[/duplicate key|already exists|E11000/i, "相同的记录已存在"],
[/not found|no such file/i, "所需内容不存在或已被移除"],
[/payload too large|document.*too large|BSON.*size|记录过大/i, "数据量过大,本次操作未完成"],
[/Validation failed|invalid payload|invalid argument|invalid request/i, "填写的内容不符合要求"],
[/disk.*full|no space left/i, "系统存储空间不足"],
[/out of memory|OOMKilled/i, "系统处理资源不足"],
[/SyntaxError|Unexpected token|JSON.*(parse|valid)|invalid json/i, "数据格式不正确"],
[/chunk.*(load|fetch)|dynamically imported module/i, "页面内容加载失败"],
[/AbortError|operation was aborted/i, "操作已中止"],
];
for (const [pattern, message] of rules) if (pattern.test(source)) return message;
const missing = text.match(/^请(?:先)?(填写|输入|选择)([^,。;]*)/);
if (missing) {
const field = missing[2]
.replace(/或勾选|要绑定的|需要上传的|需要删除的|要删除的/g, "")
.replace(/Mongo URI/gi, "数据库地址")
.replace(/MongoDB/gi, "数据库")
.replace(/bucket/gi, "存储空间")
.replace(/Token/gi, "访问凭证")
.replace(/对象 key/gi, "文件路径")
.trim();
return `${field}${missing[1] === "选择" ? "尚未选择" : "尚未填写"}`;
}
// Keep specific Chinese business facts, but remove instructions and implementation identifiers.
if (
/[\u3400-\u9fff]/.test(text) &&
!/Traceback|goroutine|<html|mongodb:|https?:\/\/|sliceSegments\.\d|\bat \S+\.(?:ts|js):/i.test(text)
) {
const plain = text
.replace(/(?:[,。;;]\s*)请[^。;;]*(?:[。;;]|$)/g, "。")
.replace(/当前页面不能编辑[^。]*/, "当前页面暂时不能修改内容")
.replace(/统一帧范围/g, "视频可用时间范围")
.replace(/被审版本/g, "标注内容")
.replace(/正式决定/g, "审核结果")
.replace(/草稿/g, "未提交的内容")
.replace(/。+/g, "。")
.trim();
if (plain && !plain.startsWith("请")) return plain;
}
if (status === 401) return "登录信息缺失或已失效";
if (status === 403) return "当前账号没有操作权限";
if (status === 404) return "所需内容不存在或已被移除";
if (status === 409) return "当前状态已变化,本次操作未完成";
if (status === 429) return "操作过于频繁";
if (status >= 500) return "系统暂时无法完成操作";
return /[\u3400-\u9fff]/.test(fallback) ? fallback : "操作暂时未完成";
}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { WorkforceStatisticsPanel } from "../components/WorkforceStatisticsPanel";
import { useReviewProjectScope } from "../hooks/useReviewProjectScope";
import { invalidSliceConsolidationCandidates } from "../lib/invalid-slice-consolidation.js";
@ -1355,7 +1356,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
return;
setFrameTimeline(null);
setTimelineState({ taskId: task.id, status: "error" });
setFrameTimelineNotice("统一帧范围加载失败,切片内容已保留;请重试,未就绪前不能修改或确认切片。");
setFrameTimelineNotice("视频时间范围加载失败,切片暂时不能编辑。");
} finally {
parentSignal?.removeEventListener("abort", abort);
}
@ -4600,7 +4601,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
)}
{reviewOnly && reviewDecision.message && (
<div role="status" className="review-decision-status rounded border border-amber-300 px-2 py-1 text-xs">
<span>{reviewDecision.message}</span>
<span>{userErrorMessage(reviewDecision.message)}</span>
{reviewDecision.pending && (
<>
<button
@ -4636,7 +4637,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
)}
{deferReviewReports && reviewAuxiliaryError && (
<p role="alert" className="text-sm text-amber-700">
{reviewAuxiliaryError}
{userErrorMessage(reviewAuxiliaryError)}
</p>
)}
{pendingTaskId !== null || leaveBlocker.state === "blocked" ? (
@ -4883,7 +4884,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
) : null}
</>
) : workSession.coordinationError ? (
<p>页面协调失败,尚未领取新任务。请刷新后重试;不会绕过页面锁。</p>
<p>当前页面暂时无法领取任务。</p>
) : (
<>
<p>此账号在本项目已有活动工作页。请切换回该页面继续,避免同时编辑。</p>
@ -5002,7 +5003,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
)}
{workPage && randomClaimNotice ? (
<p role="status" className="text-sm">
{randomClaimNotice}
{userErrorMessage(randomClaimNotice)}
</p>
) : null}
{stageResultUnknown && stageRecovery ? (
@ -5010,7 +5011,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
role="alert"
className="flex items-center justify-between gap-3 rounded-xl border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm"
>
<span>{stageRecovery.message}</span>
<span>{userErrorMessage(stageRecovery.message)}</span>
<button
type="button"
disabled={saving}
@ -5209,7 +5210,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
{annotationDirty && <p className="text-xs text-amber-700">请先确认当前编辑,再领取新任务。</p>}
{randomClaimNotice && (
<p role="status" className="break-words text-xs text-slate-600">
{randomClaimNotice}
{userErrorMessage(randomClaimNotice)}
</p>
)}
</div>
@ -5254,7 +5255,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
)}
{projectLoadError && (
<div role="alert" className="p-3 text-sm text-red-600">
任务加载失败,请点击刷新重试。
任务加载失败。
</div>
)}
{prepackageAcceptanceItems.map((item) => (
@ -5498,7 +5499,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
role="status"
className="review-session-status mb-2 flex flex-wrap items-center justify-between gap-2 rounded border border-slate-300 px-3 py-2 text-sm"
>
{reviewSessionEnabled && <span>{reviewSession.message}</span>}
{reviewSessionEnabled && <span>{userErrorMessage(reviewSession.message)}</span>}
{reviewOrdinaryContinuationVisible && (
<span
role="status"
@ -5586,7 +5587,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
onReviewProblemDelete={() => reviewDraft.requestDelete()}
onReviewEscape={reviewDraft.escape}
saving={saving}
error={error}
error={userErrorMessage(error)}
timeZone={timeZone}
draft={stats}
comment={prepackageComments[item.id] || ""}
@ -5836,7 +5837,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
labels={selectedLabels}
sliceDictionary={sliceDictionary.items}
sliceDictionaryLoading={sliceDictionary.loading}
sliceDictionaryError={sliceDictionary.error}
sliceDictionaryError={userErrorMessage(sliceDictionary.error)}
onRefreshSliceDictionary={sliceDictionary.refresh}
statuses={sliceProgress.statuses}
phase={combinedEditorPhase === "slice" ? "slice" : "annotate"}
@ -5912,7 +5913,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
discardReasons={discardReasons.items}
discardReasonsAllowManual={discardReasons.allowManual}
discardReasonsLoading={discardReasons.loading}
discardReasonsError={discardReasons.error}
discardReasonsError={userErrorMessage(discardReasons.error)}
onRefreshDiscardReasons={discardReasons.refresh}
onSliceDispositionChange={setSliceDisposition}
onSliceBoundaryChange={adjustSlice}
@ -6135,7 +6136,7 @@ export default function AnnotationOperations({ workPage = false }: { workPage?:
</fieldset>
{resliceError && (
<p role="alert" className="mt-3 text-sm text-red-300">
{resliceError}
{userErrorMessage(resliceError)}
</p>
)}
<div className="mt-6 flex justify-end gap-3">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import {
@ -97,7 +98,7 @@ export default function Audit() {
{actionError && (
<div className="flex items-center gap-3 rounded-lg border border-red-500/20 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { WorkforceStatisticsPanel } from "../components/WorkforceStatisticsPanel";
import { ProductionStatistics } from "../components/ProductionStatistics";
import React, { useCallback, useEffect, useState } from "react";
@ -178,7 +179,7 @@ export default function Dashboard() {
</div>
{errorMessage ? (
<div className="rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200">
{errorMessage}
{userErrorMessage(errorMessage)}
</div>
) : null}
{loading && !summary ? (
@ -244,7 +245,7 @@ export default function Dashboard() {
<div className="flex items-start justify-between gap-4 rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-200">
<div className="flex min-w-0 items-start gap-3">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{errorMessage}</span>
<span>{userErrorMessage(errorMessage)}</span>
</div>
<button
onClick={() => {
@ -269,7 +270,7 @@ export default function Dashboard() {
{workbenchError && (
<div className="rounded-xl border border-amber-500/20 bg-amber-500/10 px-4 py-3 text-sm text-amber-800 dark:text-amber-100">
{workbenchError}
{userErrorMessage(workbenchError)}
</div>
)}
@ -446,7 +447,7 @@ export default function Dashboard() {
)}
{run.status === "failed" && (run.failure?.message || run.error) && (
<div className="mt-1 line-clamp-2 text-[10px] text-red-600 dark:text-red-300">
{run.failure?.message || run.error}
{userErrorMessage(run.failure?.message || run.error)}
</div>
)}
<div className="mt-2 flex items-center justify-between gap-2">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Activity, AlertCircle, Boxes, GitBranch, PlayCircle } from "lucide-react";
import { useNavigate, useSearchParams } from "react-router-dom";
@ -358,7 +359,7 @@ export default function DataAssets() {
</div>
{selectionError ? (
<div className="mt-4 flex items-center gap-2 rounded-lg border border-red-500/20 bg-red-50 px-3 py-2 text-xs text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" /> {selectionError}
<AlertCircle className="h-4 w-4" /> {userErrorMessage(selectionError)}
</div>
) : null}
</section>
@ -428,7 +429,7 @@ export default function DataAssets() {
inputArtifacts={fallbackInputArtifacts}
activeGroup={activeGroup}
loading={artifactsLoading}
error={artifactsError}
error={userErrorMessage(artifactsError)}
/>
</div>
);

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import {
Activity,
@ -284,7 +285,7 @@ function TaskModal({
{error && (
<div className="flex items-start gap-2 rounded-xl border border-red-500/30 bg-red-500/10 p-3 text-sm text-red-200">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
{error}
{userErrorMessage(error)}
</div>
)}
@ -762,7 +763,7 @@ export default function DataOperations() {
{error && (
<div className="flex items-start gap-2 rounded-xl border border-amber-500/30 bg-amber-500/10 p-3 text-sm text-amber-200">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
{error}
{userErrorMessage(error)}
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useMemo, useState } from "react";
import {
AlertCircle,
@ -934,7 +935,7 @@ export default function DatabaseBrowser() {
{connectionsError ? (
<div className="flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{connectionsError}
{userErrorMessage(connectionsError)}
</div>
) : null}
@ -1017,7 +1018,7 @@ export default function DatabaseBrowser() {
{connectionActionError ? (
<div className="mt-4 flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{connectionActionError}
{userErrorMessage(connectionActionError)}
</div>
) : null}
@ -1125,14 +1126,14 @@ export default function DatabaseBrowser() {
{overviewError ? (
<div className="flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{overviewError}
{userErrorMessage(overviewError)}
</div>
) : null}
{externalTokensError ? (
<div className="flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{externalTokensError}
{userErrorMessage(externalTokensError)}
</div>
) : null}
@ -1303,7 +1304,7 @@ export default function DatabaseBrowser() {
</button>
{tokenActionError ? (
<div className="rounded-lg border border-red-500/30 bg-red-50 px-3 py-2 text-xs text-red-700 dark:bg-red-500/10 dark:text-red-200">
{tokenActionError}
{userErrorMessage(tokenActionError)}
</div>
) : null}
{revealedAPIKey ? (
@ -1554,7 +1555,7 @@ export default function DatabaseBrowser() {
</div>
{collectionActionError ? (
<div className="rounded-lg border border-red-500/30 bg-red-50 px-3 py-2 text-xs text-red-700 dark:bg-red-500/10 dark:text-red-200">
{collectionActionError}
{userErrorMessage(collectionActionError)}
</div>
) : null}
</div>
@ -1675,7 +1676,7 @@ export default function DatabaseBrowser() {
{queryError ? (
<div className="mt-4 flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{queryError}
{userErrorMessage(queryError)}
</div>
) : null}
</div>
@ -1821,7 +1822,7 @@ export default function DatabaseBrowser() {
{indexesError ? (
<div className="mt-4 flex items-center gap-2 rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4" />
{indexesError}
{userErrorMessage(indexesError)}
</div>
) : null}
</div>
@ -1934,7 +1935,7 @@ export default function DatabaseBrowser() {
/>
{documentActionError ? (
<div className="rounded-lg border border-red-500/30 bg-red-50 px-3 py-2 text-xs text-red-700 dark:bg-red-500/10 dark:text-red-200">
{documentActionError}
{userErrorMessage(documentActionError)}
</div>
) : null}
<div className="rounded-xl border border-[color:var(--app-border)] bg-[color:var(--app-inset)] p-3 text-xs text-slate-500 dark:text-gray-400">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { lazy, Suspense, useDeferredValue, useState, useMemo, useEffect } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { useTimeZone } from "../context/TimeZoneContext";
@ -753,7 +754,7 @@ export default function Monitoring() {
if (artifactLineageError) {
return (
<div className="rounded-xl border border-red-500/20 bg-red-500/10 p-4 text-xs text-red-700 dark:text-red-200">
{artifactLineageError}
{userErrorMessage(artifactLineageError)}
</div>
);
}
@ -1000,7 +1001,7 @@ export default function Monitoring() {
<div className="flex min-h-[280px] items-center justify-center">
<div className="flex max-w-md items-start gap-3 rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200">
<XCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{modalError}</span>
<span>{userErrorMessage(modalError)}</span>
</div>
</div>
) : (
@ -1535,7 +1536,7 @@ export default function Monitoring() {
{(runsError || runActionError) && (
<div className="flex items-start gap-3 rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200">
<XCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{runActionError || runsError}</span>
<span>{userErrorMessage(runActionError || runsError)}</span>
</div>
)}
@ -1669,10 +1670,10 @@ export default function Monitoring() {
{run.status === "failed" && (run.failure?.message || run.error) && (
<div
className="mt-1 max-w-[360px] truncate text-[11px] text-red-700 dark:text-red-300"
title={run.failure?.message || run.error}
title={userErrorMessage(run.failure?.message || run.error)}
>
{run.failure?.nodeId ? `失败节点 ${run.failure.nodeId}:` : "失败摘要:"}
{run.failure?.message || run.error}
{userErrorMessage(run.failure?.message || run.error)}
</div>
)}
</td>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import {
AlertCircle,
@ -1145,7 +1146,7 @@ export default function ObjectStorageBrowser() {
if (previewError) {
return (
<div className="rounded-2xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-700 dark:text-red-100">
{previewError}
{userErrorMessage(previewError)}
</div>
);
}
@ -1248,12 +1249,12 @@ export default function ObjectStorageBrowser() {
<div className="mt-4 space-y-2">
{connectionsError && (
<div className="rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-100">
{connectionsError}
{userErrorMessage(connectionsError)}
</div>
)}
{connectionActionError && (
<div className="rounded-xl border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-100">
{connectionActionError}
{userErrorMessage(connectionActionError)}
</div>
)}
{connectionActionMessage && (
@ -1424,7 +1425,7 @@ export default function ObjectStorageBrowser() {
{overviewError && (
<div className="mt-3 rounded-xl border border-red-500/20 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-100">
{overviewError}
{userErrorMessage(overviewError)}
</div>
)}
@ -1540,7 +1541,7 @@ export default function ObjectStorageBrowser() {
{objectsError && (
<div className="mt-4 rounded-xl border border-red-500/20 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-100">
{objectsError}
{userErrorMessage(objectsError)}
</div>
)}
@ -1731,7 +1732,7 @@ export default function ObjectStorageBrowser() {
{objectActionError && (
<div className="mt-4 rounded-xl border border-red-500/20 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-100">
{objectActionError}
{userErrorMessage(objectActionError)}
</div>
)}
{objectActionMessage && (

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { useCallback, useEffect, useMemo, useState, type ReactNode } from "react";
import {
Activity,
@ -528,7 +529,7 @@ export default function ObjectSync() {
<AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" />
<div>
<div className="font-medium">控制面暂不可用</div>
<div className="mt-1 text-xs leading-5 text-rose-300/80">{error}</div>
<div className="mt-1 text-xs leading-5 text-rose-300/80">{userErrorMessage(error)}</div>
</div>
</div>
) : null}
@ -824,7 +825,7 @@ export default function ObjectSync() {
<td className="px-5 py-4">
<CapabilityBadge state={space.capability.state} />
{space.capability.probeError ? (
<div className="mt-2 max-w-xs text-[11px] text-rose-300">{space.capability.probeError}</div>
<div className="mt-2 max-w-xs text-[11px] text-rose-300">{userErrorMessage(space.capability.probeError)}</div>
) : null}
</td>
<td className="px-5 py-4">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useCallback, useEffect, useRef, useState } from "react";
import {
Cpu,
@ -1224,7 +1225,7 @@ export default function Operators() {
{actionError && !isModalOpen && (
<div className="flex items-center gap-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
)}
@ -1578,7 +1579,7 @@ export default function Operators() {
{actionError && (
<div className="flex items-center gap-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
)}
@ -2670,7 +2671,7 @@ export default function Operators() {
>
{lightweightFilesError ? (
<div className="rounded border border-red-500/20 bg-red-500/10 px-3 py-2 text-[11px] text-red-700 dark:text-red-200">
{lightweightFilesError}
{userErrorMessage(lightweightFilesError)}
</div>
) : lightweightFilesLoading && !lightweightFiles ? (
<div className="flex items-center gap-2 px-2 py-3 text-xs text-slate-500 dark:text-gray-500">
@ -2884,7 +2885,7 @@ export default function Operators() {
{lightweightFileError && (
<div className="border-b border-red-500/20 bg-red-500/10 px-4 py-2 text-xs text-red-700 dark:text-red-200">
{lightweightFileError}
{userErrorMessage(lightweightFileError)}
</div>
)}
@ -3096,7 +3097,7 @@ export default function Operators() {
{aiError && (
<div className="p-3 bg-red-500/10 border border-red-500/20 rounded-lg flex items-center gap-3 text-red-500 text-xs">
<AlertCircle className="w-4 h-4 shrink-0" />
{aiError}
{userErrorMessage(aiError)}
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { Blocks, Box, CheckCircle2, Loader2, LockKeyhole } from "lucide-react";
import { PageSubnav } from "../components/PageSubnav";
import PluginSettingsPanel from "../components/PluginSettingsPanel";
@ -16,7 +17,7 @@ export default function Plugins() {
</div>
{error ? (
<div className="rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">{error}</div>
<div className="rounded-xl border border-red-500/30 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">{userErrorMessage(error)}</div>
) : null}
<section id="catalog" className="scroll-mt-24 space-y-4">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState, useDeferredValue } from "react";
import { continuousProcessingStatus } from "../lib/continuous-processing.js";
import { Link, useParams, useNavigate } from "react-router-dom";
@ -536,7 +537,7 @@ export default function ProjectDetail() {
<AlertCircle className="w-5 h-5 shrink-0" />
<div>
<div className="font-semibold">加载项目详情失败</div>
<div className="text-sm text-red-200/80">{loadError}</div>
<div className="text-sm text-red-200/80">{userErrorMessage(loadError)}</div>
</div>
</div>
<button
@ -1400,7 +1401,7 @@ export default function ProjectDetail() {
{activeTab === "versions" && versionsError && (
<div className="flex items-center gap-2 rounded-xl border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-600 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
{versionsError}
{userErrorMessage(versionsError)}
</div>
)}
{visibleWorkflows.map((wf) => {
@ -1910,7 +1911,7 @@ export default function ProjectDetail() {
{runsError && (
<div className="m-4 flex items-center gap-2 rounded-lg border border-red-500/20 bg-red-500/10 p-3 text-xs text-red-700 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{runsError}</span>
<span>{userErrorMessage(runsError)}</span>
</div>
)}
@ -1948,10 +1949,10 @@ export default function ProjectDetail() {
{run.status === "failed" && (run.failure?.message || run.error) && (
<div
className="mt-1 max-w-[360px] truncate text-[11px] text-red-500 dark:text-red-300"
title={run.failure?.message || run.error}
title={userErrorMessage(run.failure?.message || run.error)}
>
{run.failure?.nodeId ? `失败节点 ${run.failure.nodeId}:` : "失败摘要:"}
{run.failure?.message || run.error}
{userErrorMessage(run.failure?.message || run.error)}
</div>
)}
</td>
@ -2174,7 +2175,7 @@ export default function ProjectDetail() {
</label>
{deleteWorkflowError && (
<div className="rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-200">
{deleteWorkflowError}
{userErrorMessage(deleteWorkflowError)}
</div>
)}
</div>
@ -2508,7 +2509,7 @@ export default function ProjectDetail() {
{automationError ? (
<div className="flex items-center gap-2 rounded-lg border border-red-500/20 bg-red-500/10 p-3 text-sm text-red-700 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
{automationError}
{userErrorMessage(automationError)}
</div>
) : null}
@ -2928,10 +2929,10 @@ export default function ProjectDetail() {
{record.error ? (
<div
className="mt-1 max-w-[320px] text-[10px] text-red-700 dark:text-red-300"
title={record.error}
title={userErrorMessage(record.error)}
>
{record.failedNodeId ? `失败节点 ${record.failedNodeId}:` : "失败原因:"}
{record.error}
{userErrorMessage(record.error)}
</div>
) : null}
</td>
@ -3051,7 +3052,7 @@ export default function ProjectDetail() {
<div className="shrink-0 space-y-3 border-t border-[color:var(--app-border)] bg-[color:var(--app-inset)] px-6 py-4">
{automationError ? (
<p role="alert" className="text-sm text-red-700 dark:text-red-300">
{automationError}
{userErrorMessage(automationError)}
</p>
) : null}
{automationNotice ? (
@ -3139,7 +3140,7 @@ export default function ProjectDetail() {
{captureActionError ? (
<div className="flex items-start gap-2 rounded-lg border border-red-500/20 bg-red-500/10 p-3 text-xs text-red-700 dark:text-red-200">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
{captureActionError}
{userErrorMessage(captureActionError)}
</div>
) : null}
<label className="block space-y-1.5">
@ -3248,7 +3249,7 @@ export default function ProjectDetail() {
</div>
) : historyError ? (
<div className="rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-xs text-red-700 dark:text-red-300">
{historyError}
{userErrorMessage(historyError)}
</div>
) : historyRuns.length === 0 ? (
<div className="flex flex-col items-center justify-center py-12 text-slate-500 dark:text-gray-500 gap-2">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { ProjectDeletionDialog, ProjectDeletionHistory } from "../components/ProjectDeletionDialog";
import { BatchProjectDeletionDialog } from "../components/BatchProjectDeletionDialog";
import React, { useEffect, useRef, useState } from "react";
@ -518,7 +519,7 @@ export default function Projects() {
{actionError && (
<div className="flex items-center gap-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
)}
@ -893,7 +894,7 @@ export default function Projects() {
className="flex items-start gap-2 rounded-lg border border-red-500/25 bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200"
>
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
) : null}
{bucketLoadWarning ? (
@ -954,7 +955,7 @@ export default function Projects() {
</select>
</label>
{templateLoadError && (
<p className="text-xs text-amber-700 dark:text-amber-300">{templateLoadError}</p>
<p className="text-xs text-amber-700 dark:text-amber-300">{userErrorMessage(templateLoadError)}</p>
)}
{usesPublicSupplierPool && (
<div className="space-y-2 rounded-lg border border-[color:var(--app-border)] p-3">

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState, useDeferredValue, useMemo } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { useTimeZone } from "../context/TimeZoneContext";
@ -320,7 +321,7 @@ export default function Runs() {
{runsError && (
<div className="m-4 flex items-center gap-2 rounded-lg border border-red-500/20 bg-red-50 p-3 text-xs text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{runsError}</span>
<span>{userErrorMessage(runsError)}</span>
</div>
)}
@ -358,10 +359,10 @@ export default function Runs() {
{run.status === "failed" && (run.failure?.message || run.error) && (
<div
className="mt-1 max-w-[360px] truncate text-[11px] text-red-600 dark:text-red-300"
title={run.failure?.message || run.error}
title={userErrorMessage(run.failure?.message || run.error)}
>
{run.failure?.nodeId ? `失败节点 ${run.failure.nodeId}:` : "失败摘要:"}
{run.failure?.message || run.error}
{userErrorMessage(run.failure?.message || run.error)}
</div>
)}
</td>
@ -601,7 +602,7 @@ export default function Runs() {
<div className="flex min-h-[280px] items-center justify-center">
<div className="flex max-w-md items-start gap-3 rounded-xl border border-red-500/20 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<XCircle className="mt-0.5 h-4 w-4 shrink-0" />
<span>{modalError}</span>
<span>{userErrorMessage(modalError)}</span>
</div>
</div>
) : (

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useMemo, useState } from "react";
import { AlertCircle, ClipboardList, Eye, Loader2, RefreshCw, Search, Send } from "lucide-react";
import { useTimeZone } from "../context/TimeZoneContext";
@ -119,7 +120,7 @@ export default function Sampling() {
<div className="flex flex-wrap items-center justify-between gap-3 rounded-lg border border-red-500/20 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<div className="flex min-w-0 items-center gap-3">
<AlertCircle className="h-4 w-4 shrink-0" />
<span className="break-words">{loadError || actionError}</span>
<span className="break-words">{userErrorMessage(loadError || actionError)}</span>
</div>
{loadError && (
<button

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { ProductionStatisticsScope } from "../components/ProductionStatisticsScope";
import React, { useEffect, useState } from "react";
import { AlertCircle, Bot, CheckCircle2, Clock3, Cpu, Database, GitBranch, Loader2, Save, Server } from "lucide-react";
@ -148,7 +149,7 @@ export default function Settings() {
{errorMessage && (
<div className="bg-red-500/10 border border-red-500/20 rounded-xl px-4 py-3 text-sm text-red-700 dark:text-red-300 flex items-center gap-2">
<AlertCircle className="w-4 h-4 shrink-0" />
{errorMessage}
{userErrorMessage(errorMessage)}
</div>
)}
</div>
@ -201,7 +202,7 @@ export default function Settings() {
{errorMessage && (
<div className="bg-red-500/10 border border-red-500/20 rounded-xl px-4 py-3 text-sm text-red-700 dark:text-red-300 flex items-center gap-2">
<AlertCircle className="w-4 h-4 shrink-0" />
{errorMessage}
{userErrorMessage(errorMessage)}
</div>
)}
@ -343,7 +344,7 @@ export default function Settings() {
<Cpu className="w-4 h-4 text-amber-700 dark:text-amber-300" />
<div>
<p className="text-sm font-semibold text-[color:var(--app-text)]">GPU 调度能力</p>
<p className="text-xs text-slate-500 dark:text-gray-500">{workerCapacityError || gpuStatus.detail}</p>
<p className="text-xs text-slate-500 dark:text-gray-500">{userErrorMessage(workerCapacityError || gpuStatus.detail)}</p>
</div>
</div>
<span

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useEffect, useState } from "react";
import {
Plus,
@ -525,7 +526,7 @@ export default function Templates() {
{actionError && (
<div className="flex items-center gap-3 rounded-lg border border-red-500/20 bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-200">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{actionError}</span>
<span>{userErrorMessage(actionError)}</span>
</div>
)}

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import { SupplierDeletionDialog, supplierDeletionStatus } from "../components/SupplierDeletionDialog";
import React, { useCallback, useEffect, useState } from "react";
import { cn } from "../lib/utils";
@ -303,7 +304,7 @@ export default function Users() {
<div className="flex flex-wrap items-center justify-between gap-3 rounded-md border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-300">
<div className="flex min-w-0 items-center gap-2">
<AlertCircle className="h-4 w-4 shrink-0" />
<span className="break-words">{error}</span>
<span className="break-words">{userErrorMessage(error)}</span>
</div>
{users.length === 0 && !isLoadingUsers && (
<button
@ -617,7 +618,7 @@ export default function Users() {
</label>
{supplierError && (
<p role="alert" className="text-sm text-red-600">
{supplierError}
{userErrorMessage(supplierError)}
</p>
)}
</div>
@ -674,7 +675,7 @@ export default function Users() {
role="alert"
className="rounded-lg border border-red-300 bg-red-50 p-3 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300"
>
{error}
{userErrorMessage(error)}
</div>
) : null}
<p className="text-xs text-slate-500 dark:text-slate-400">账号仅有一个角色,项目职责与账号角色一致。</p>

View File

@ -1,3 +1,4 @@
import { userErrorMessage } from "../lib/user-error-message.js";
import React, { useState, useCallback, memo, useEffect, useMemo, useRef } from "react";
import { Logo } from "../components/Logo";
import { useTheme } from "../context/ThemeContext";
@ -4198,7 +4199,7 @@ export default function WorkflowEditor() {
{canManage && (
<WorkflowSaveControl
state={saveState}
error={saveError}
error={userErrorMessage(saveError)}
blocked={isReadOnly || hasBlockingGraphIssue}
blockedMessage={isReadOnly ? editorLockState.message : blockingGraphIssueMessage}
onSave={() => void handleSave()}
@ -4276,7 +4277,7 @@ export default function WorkflowEditor() {
{editorLoadError && (
<div className="shrink-0 border-b border-red-500/20 bg-red-500/10 px-6 py-2 text-[11px] text-red-700 dark:text-red-200 flex items-center justify-between gap-3">
<span>{editorLoadError}</span>
<span>{userErrorMessage(editorLoadError)}</span>
<button
type="button"
onClick={() => setEditorReloadToken((current) => current + 1)}
@ -4325,7 +4326,7 @@ export default function WorkflowEditor() {
{saveError && !draftRecovery && (
<div className="shrink-0 border-b border-red-500/20 bg-red-500/10 px-6 py-2 text-[11px] text-red-700 dark:text-red-200">
保存失败:{saveError}。本地草稿已保留,可修改后重试。
保存失败:{userErrorMessage(saveError)}。未保存的内容已保留。
</div>
)}
@ -4373,7 +4374,7 @@ export default function WorkflowEditor() {
)}
</div>
)}
{activeRunError && <div className="text-[11px] text-red-700 dark:text-red-300">{activeRunError}</div>}
{activeRunError && <div className="text-[11px] text-red-700 dark:text-red-300">{userErrorMessage(activeRunError)}</div>}
{activeRun && (
<div className="text-[10px] text-slate-500 dark:text-gray-500">
运行会停留在当前画布,节点高亮和连线动画会实时反映真实执行进度。
@ -4441,7 +4442,7 @@ export default function WorkflowEditor() {
{workflowRunsError && (
<div className="rounded border border-red-500/20 bg-red-500/10 px-3 py-2 text-[11px] text-red-700 dark:text-red-200">
{workflowRunsError}
{userErrorMessage(workflowRunsError)}
</div>
)}
@ -4496,7 +4497,7 @@ export default function WorkflowEditor() {
<div>尝试次数 {run.attempt || 1}</div>
{run.parentRunId && <div className="break-all">父运行 {run.parentRunId}</div>}
{run.restartFromNodeId && <div>重跑起点 {run.restartFromNodeId}</div>}
{run.error && <div className="line-clamp-2 text-red-700 dark:text-red-200">{run.error}</div>}
{run.error && <div className="line-clamp-2 text-red-700 dark:text-red-200">{userErrorMessage(run.error)}</div>}
</div>
</button>
);
@ -5080,7 +5081,7 @@ export default function WorkflowEditor() {
{selectedNodeExecution.error && (
<div className="rounded border border-red-500/30 bg-red-500/10 px-3 py-2 text-[10px] text-red-700 dark:text-red-200">
{selectedNodeExecution.error}
{userErrorMessage(selectedNodeExecution.error)}
</div>
)}
@ -5122,7 +5123,7 @@ export default function WorkflowEditor() {
</div>
{liveRunLogsError && (
<div className="rounded border border-red-500/30 bg-red-500/10 px-2 py-1.5 text-[10px] text-red-700 dark:text-red-200">
{liveRunLogsError}
{userErrorMessage(liveRunLogsError)}
</div>
)}
<div
@ -5675,7 +5676,7 @@ export default function WorkflowEditor() {
{storageConnectionsError && (
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-700 dark:text-amber-200">
{storageConnectionsError}
{userErrorMessage(storageConnectionsError)}
</div>
)}
@ -6027,7 +6028,7 @@ export default function WorkflowEditor() {
</div>
) : sourceStateError ? (
<div className="rounded border border-red-500/20 bg-red-500/10 px-2 py-3 text-[11px] text-red-700 dark:text-red-200">
{sourceStateError}
{userErrorMessage(sourceStateError)}
</div>
) : !sourceState?.supported ? (
<div className="rounded border border-[color:var(--app-border)] bg-[color:var(--app-inset)] px-2 py-3 text-[11px] text-slate-600 dark:text-gray-400">
@ -6194,7 +6195,7 @@ export default function WorkflowEditor() {
{mongoConnectionsError && (
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-700 dark:text-amber-200">
{mongoConnectionsError}
{userErrorMessage(mongoConnectionsError)}
</div>
)}
@ -6296,7 +6297,7 @@ export default function WorkflowEditor() {
{storageConnectionsError && (
<div className="rounded border border-amber-500/20 bg-amber-500/10 px-2 py-1 text-[10px] text-amber-700 dark:text-amber-200">
{storageConnectionsError}
{userErrorMessage(storageConnectionsError)}
</div>
)}
@ -6646,7 +6647,7 @@ export default function WorkflowEditor() {
{ossBrowseError && !isOssBrowsing && (
<p className="text-[9px] text-amber-700 dark:text-amber-400 break-all">
{ossBrowseError}
{userErrorMessage(ossBrowseError)}
</p>
)}
</div>
@ -6959,7 +6960,7 @@ export default function WorkflowEditor() {
)}
{selectedNodeRequestsGPU && workerCapacityError && (
<p className="rounded border border-red-500/20 bg-red-500/10 px-2 py-1 text-[10px] leading-snug text-red-700 dark:text-red-300">
{workerCapacityError}
{userErrorMessage(workerCapacityError)}
</p>
)}
</div>
@ -7779,7 +7780,7 @@ export default function WorkflowEditor() {
) : ossBrowseError ? (
<div className="h-64 flex flex-col items-center justify-center text-center">
<Info className="w-8 h-8 text-amber-700 dark:text-amber-400 mb-2" />
<p className="text-sm text-amber-700 dark:text-amber-300 break-all">{ossBrowseError}</p>
<p className="text-sm text-amber-700 dark:text-amber-300 break-all">{userErrorMessage(ossBrowseError)}</p>
</div>
) : ossObjects.length === 0 ? (
<div className="h-64 flex flex-col items-center justify-center text-center">

View File

@ -4,12 +4,12 @@ import test from "node:test";
import { getActionErrorMessage, recoverableGatewayStatus } from "../../src/lib/action-errors.js";
test("action error message prefers non-empty Error messages", () => {
assert.equal(getActionErrorMessage(new Error(" forbidden "), "保存失败"), "forbidden");
assert.equal(getActionErrorMessage(new Error(" forbidden "), "保存失败"), "当前账号没有操作权限");
});
test("action error message accepts plain string and object messages", () => {
assert.equal(getActionErrorMessage(" request timed out ", "操作失败"), "request timed out");
assert.equal(getActionErrorMessage({ message: " invalid payload " }, "操作失败"), "invalid payload");
assert.equal(getActionErrorMessage(" request timed out ", "操作失败"), "系统响应超时,暂时无法确认操作结果");
assert.equal(getActionErrorMessage({ message: " invalid payload " }, "操作失败"), "填写的内容不符合要求");
});
test("action error message falls back for empty or unsupported errors", () => {

View File

@ -35,7 +35,7 @@ test("only an authoritative stage transition proves completion", () => {
});
test("version conflicts are actionable, not silently retried", () => {
assert.match(getActionErrorMessage({ code: "version_conflict" }), /任务版本已更新/);
assert.match(getActionErrorMessage({ code: "version_conflict" }), /内容已被修改,本次操作未完成/);
});
test("production roles can open their existing personal dashboard, not other stages", () => {

View File

@ -0,0 +1,69 @@
import assert from "node:assert/strict";
import test from "node:test";
import { userErrorMessage } from "../../src/lib/user-error-message.js";
import { getActionErrorMessage } from "../../src/lib/action-errors.js";
test("common API errors explain the problem without implementation details", () => {
const cases = [
["invalid phone or password", "账号或密码不正确"],
["API token is required", "登录信息缺失或已失效"],
["csrf token mismatch", "当前登录状态无法完成这次操作"],
["permission denied", "当前账号没有操作权限"],
["E11000 duplicate key users phone", "相同的记录已存在"],
["File not found: /workspace/private", "所需内容不存在或已被移除"],
["Validation failed (sliceSegments.1.name: invalid)", "填写的内容不符合要求"],
["已保存草稿已有新版本,请核对后再保存", "这条审核意见已被修改,本次保存未成功"],
["提交前校验未通过;草稿已保留,请修正后重新确认", "审核内容有不符合要求的地方,未能提交"],
["worker lost heartbeat", "任务处理已中断"],
["no space left on device", "系统存储空间不足"],
["OOMKilled", "系统处理资源不足"],
];
for (const [input, expected] of cases) assert.equal(userErrorMessage(input), expected);
});
test("unknown network and submission outcomes must never become confirmed failures", () => {
for (const text of ["Failed to fetch", "request timed out", "deadline exceeded"]) {
assert.match(userErrorMessage(text), /暂时无法确认操作结果/);
assert.doesNotMatch(userErrorMessage(text), /未成功|保存失败|提交失败/);
}
assert.equal(userErrorMessage("暂时无法确认是否保存成功,文字仍保留。"), "暂时无法确认是否保存成功,文字仍保留。");
});
test("rendering does not mutate errors, status, codes, or diagnostics", () => {
const error = Object.assign(new Error("unmapped server internals"), {
code: "unknown",
status: 503,
requestId: "abc",
details: { cause: "database" },
});
const before = { message: error.message, stack: error.stack, ...error };
assert.equal(getActionErrorMessage(error), "系统暂时无法完成操作");
assert.deepEqual({ message: error.message, stack: error.stack, ...error }, before);
});
test("Chinese business facts and empty states survive display formatting", () => {
assert.equal(userErrorMessage("手机号格式不正确,请重新填写。"), "手机号格式不正确。");
assert.equal(userErrorMessage("删除失败;已成功删除的项目不受影响。"), "删除失败;已成功删除的项目不受影响。");
assert.equal(userErrorMessage("已保存"), "已保存");
assert.equal(userErrorMessage(null), "");
assert.equal(userErrorMessage(""), "");
assert.equal(getActionErrorMessage(new Error("opaque_exception"), "视频加载失败"), "视频加载失败");
});
test("formatting remains stable when an API error passes through a page formatter", () => {
for (const error of [
new Error("forbidden"),
{ code: "version_conflict", message: "conflict" },
new Error("Failed to fetch"),
]) {
const once = getActionErrorMessage(error);
assert.equal(userErrorMessage(once), once);
}
});
test("missing form fields still identify what is missing", () => {
assert.equal(userErrorMessage("请填写连接名称。"), "连接名称尚未填写");
assert.equal(userErrorMessage("请先选择 bucket。"), "存储空间尚未选择");
assert.equal(userErrorMessage("请输入对象 key。"), "文件路径尚未填写");
assert.equal(userErrorMessage("请选择供应商,无外部供应商请选择默认供应商。"), "供应商尚未选择");
});