Update Failure Messaging and Localization in Executor

- Refactored failure message construction to use concise phase names instead of full error messages, improving clarity in UI feedback.
- Updated localization support for failure messages, ensuring accurate translations for various phases in both English and Chinese.
- Added unit tests to validate the new failure message format and localization functionality.
This commit is contained in:
Max 2026-01-24 10:17:51 +08:00
parent d590bd7557
commit de9e2c589b
2 changed files with 34 additions and 6 deletions

View file

@ -153,11 +153,10 @@ func (e *Executor) Execute(ctx *robottypes.Context, robot *robottypes.Robot, tri
exec.Error = err.Error()
// Update UI field for failure with i18n
// Use concise phase name, NOT the full error message (error is in exec.Error)
failedPrefix := getLocalizedMessage(locale, "failed_prefix")
failureMsg := failedPrefix + err.Error()
if len(failureMsg) > 100 {
failureMsg = failureMsg[:100] + "..."
}
phaseName := getLocalizedMessage(locale, "phase_"+string(phase))
failureMsg := failedPrefix + phaseName
e.updateUIFields(ctx, exec, "", failureMsg)
log.With(log.F{
@ -383,8 +382,15 @@ var uiMessages = map[string]map[string]string{
"planning_goals": "Planning goals...",
"breaking_down_tasks": "Breaking down tasks...",
"completed": "Completed",
"failed_prefix": "Failed: ",
"failed_prefix": "Failed at ",
"task_prefix": "Task",
// Phase names for failure messages
"phase_inspiration": "inspiration",
"phase_goals": "goals",
"phase_tasks": "tasks",
"phase_run": "execution",
"phase_delivery": "delivery",
"phase_learning": "learning",
},
"zh": {
"preparing": "准备中...",
@ -396,8 +402,15 @@ var uiMessages = map[string]map[string]string{
"planning_goals": "规划目标...",
"breaking_down_tasks": "分解任务...",
"completed": "已完成",
"failed_prefix": "失败: ",
"failed_prefix": "失败",
"task_prefix": "任务",
// Phase names for failure messages
"phase_inspiration": "灵感阶段",
"phase_goals": "目标阶段",
"phase_tasks": "任务阶段",
"phase_run": "执行阶段",
"phase_delivery": "交付阶段",
"phase_learning": "学习阶段",
},
}

View file

@ -105,6 +105,9 @@ func TestGetLocalizedMessage(t *testing.T) {
"event_prefix", "event_triggered", "analyzing_context",
"planning_goals", "breaking_down_tasks", "completed",
"failed_prefix", "task_prefix",
// Phase names for failure messages
"phase_inspiration", "phase_goals", "phase_tasks",
"phase_run", "phase_delivery", "phase_learning",
}
for _, key := range keys {
msg := getLocalizedMessage("en", key)
@ -118,12 +121,24 @@ func TestGetLocalizedMessage(t *testing.T) {
"event_prefix", "event_triggered", "analyzing_context",
"planning_goals", "breaking_down_tasks", "completed",
"failed_prefix", "task_prefix",
// Phase names for failure messages
"phase_inspiration", "phase_goals", "phase_tasks",
"phase_run", "phase_delivery", "phase_learning",
}
for _, key := range keys {
msg := getLocalizedMessage("zh", key)
assert.NotEqual(t, key, msg, "Chinese message should exist for key: %s", key)
}
})
t.Run("failure_message_is_concise", func(t *testing.T) {
// Test that failure messages use phase names, not full error text
enFailure := getLocalizedMessage("en", "failed_prefix") + getLocalizedMessage("en", "phase_inspiration")
assert.Equal(t, "Failed at inspiration", enFailure)
zhFailure := getLocalizedMessage("zh", "failed_prefix") + getLocalizedMessage("zh", "phase_inspiration")
assert.Equal(t, "失败于灵感阶段", zhFailure)
})
}
// ============================================================================