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:
parent
d590bd7557
commit
de9e2c589b
2 changed files with 34 additions and 6 deletions
|
|
@ -153,11 +153,10 @@ func (e *Executor) Execute(ctx *robottypes.Context, robot *robottypes.Robot, tri
|
||||||
exec.Error = err.Error()
|
exec.Error = err.Error()
|
||||||
|
|
||||||
// Update UI field for failure with i18n
|
// 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")
|
failedPrefix := getLocalizedMessage(locale, "failed_prefix")
|
||||||
failureMsg := failedPrefix + err.Error()
|
phaseName := getLocalizedMessage(locale, "phase_"+string(phase))
|
||||||
if len(failureMsg) > 100 {
|
failureMsg := failedPrefix + phaseName
|
||||||
failureMsg = failureMsg[:100] + "..."
|
|
||||||
}
|
|
||||||
e.updateUIFields(ctx, exec, "", failureMsg)
|
e.updateUIFields(ctx, exec, "", failureMsg)
|
||||||
|
|
||||||
log.With(log.F{
|
log.With(log.F{
|
||||||
|
|
@ -383,8 +382,15 @@ var uiMessages = map[string]map[string]string{
|
||||||
"planning_goals": "Planning goals...",
|
"planning_goals": "Planning goals...",
|
||||||
"breaking_down_tasks": "Breaking down tasks...",
|
"breaking_down_tasks": "Breaking down tasks...",
|
||||||
"completed": "Completed",
|
"completed": "Completed",
|
||||||
"failed_prefix": "Failed: ",
|
"failed_prefix": "Failed at ",
|
||||||
"task_prefix": "Task",
|
"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": {
|
"zh": {
|
||||||
"preparing": "准备中...",
|
"preparing": "准备中...",
|
||||||
|
|
@ -396,8 +402,15 @@ var uiMessages = map[string]map[string]string{
|
||||||
"planning_goals": "规划目标...",
|
"planning_goals": "规划目标...",
|
||||||
"breaking_down_tasks": "分解任务...",
|
"breaking_down_tasks": "分解任务...",
|
||||||
"completed": "已完成",
|
"completed": "已完成",
|
||||||
"failed_prefix": "失败: ",
|
"failed_prefix": "失败于",
|
||||||
"task_prefix": "任务",
|
"task_prefix": "任务",
|
||||||
|
// Phase names for failure messages
|
||||||
|
"phase_inspiration": "灵感阶段",
|
||||||
|
"phase_goals": "目标阶段",
|
||||||
|
"phase_tasks": "任务阶段",
|
||||||
|
"phase_run": "执行阶段",
|
||||||
|
"phase_delivery": "交付阶段",
|
||||||
|
"phase_learning": "学习阶段",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,9 @@ func TestGetLocalizedMessage(t *testing.T) {
|
||||||
"event_prefix", "event_triggered", "analyzing_context",
|
"event_prefix", "event_triggered", "analyzing_context",
|
||||||
"planning_goals", "breaking_down_tasks", "completed",
|
"planning_goals", "breaking_down_tasks", "completed",
|
||||||
"failed_prefix", "task_prefix",
|
"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 {
|
for _, key := range keys {
|
||||||
msg := getLocalizedMessage("en", key)
|
msg := getLocalizedMessage("en", key)
|
||||||
|
|
@ -118,12 +121,24 @@ func TestGetLocalizedMessage(t *testing.T) {
|
||||||
"event_prefix", "event_triggered", "analyzing_context",
|
"event_prefix", "event_triggered", "analyzing_context",
|
||||||
"planning_goals", "breaking_down_tasks", "completed",
|
"planning_goals", "breaking_down_tasks", "completed",
|
||||||
"failed_prefix", "task_prefix",
|
"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 {
|
for _, key := range keys {
|
||||||
msg := getLocalizedMessage("zh", key)
|
msg := getLocalizedMessage("zh", key)
|
||||||
assert.NotEqual(t, key, msg, "Chinese message should exist for key: %s", 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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue