flipped-aurora/gin-vue-admin · error
方法 %s 未注册
Error message
方法 %s 未注册
What it means
validateTask verifies that a method-executor timed task references a registered method. task.Get(t.MethodName) looks the name up in the task registry; if absent, creation/update is rejected with '方法 %s 未注册'. This guards against persisting tasks that could never be dispatched at runtime.
Source
Thrown at server/service/system/sys_timed_task.go:55
}
if err != nil {
return fmt.Errorf("cron 表达式非法: %w", err)
}
return nil
}
// validateTask 落库前统一校验(创建/更新共用)
func (s *TimedTaskService) validateTask(t *system.SysTimedTask) error {
if t.Name == "" {
return errors.New("任务名不能为空")
}
if err := s.ValidateSpec(t.Spec, t.WithSeconds); err != nil {
return err
}
switch t.ExecutorType {
case system.TimedTaskExecutorMethod:
if _, ok := task.Get(t.MethodName); !ok {
return fmt.Errorf("方法 %s 未注册", t.MethodName)
}
if len(t.Params) > 0 && !json.Valid(t.Params) {
return errors.New("params 必须是合法 JSON")
}
case system.TimedTaskExecutorHTTP:
u, err := url.Parse(t.HttpUrl)
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
return errors.New("httpUrl 必须是合法的 http/https 地址")
}
if len(t.HttpHeader) > 0 {
var hdr map[string]string
if err := json.Unmarshal(t.HttpHeader, &hdr); err != nil {
return errors.New(`httpHeader 必须是 {"Key":"Value"} 形式的 JSON 对象`)
}
}
default:
return fmt.Errorf("executorType 必须为 %s 或 %s", system.TimedTaskExecutorMethod, system.TimedTaskExecutorHTTP)
}View on GitHub (pinned to 3136500ef3)
Solutions
- Check the exact registered name at the task.Add call site and fix MethodName to match
- Verify the code/plugin that registers the method is actually loaded at startup
- List available registered methods (or add debug logging around task.Get) to discover valid names
- If the method was removed or renamed, update the task to a currently registered method
Example fix
// before
{ "executorType": "method", "methodName": "ClearCacheJob" } // never registered
// after
// in registration code:
task.Add("system.ClearCache", func(...) error { ... })
// in task:
{ "executorType": "method", "methodName": "system.ClearCache" } Defensive patterns
Strategy: validation
Validate before calling
// Go: check registry membership before creating a method task
if _, ok := task.Get(methodName); !ok {
return fmt.Errorf("方法 %s 未注册", methodName)
} Type guard
// Go: registered-method guard
func methodRegistered(name string) bool {
_, ok := task.Get(name)
return ok
} Try / catch
err := svc.CreateTimedTask(t)
if err != nil && strings.Contains(err.Error(), "未注册") {
// inspect registry / task.Add call sites, fix MethodName, resubmit
return fmt.Errorf("请使用已注册的方法名: %w", err)
} Prevention
- Copy MethodName from the exact string passed to task.Add — avoid retyping
- Ensure the plugin/service registering the method is loaded before task creation
- When renaming a method, migrate existing task rows referencing the old name
- Maintain a single source of truth (constants) for registered method names
When it happens
Trigger: Creating or updating a timed task with ExecutorType=TimedTaskExecutorMethod where MethodName does not match any method registered in the task registry (typo, method never registered, or plugin providing the method not loaded).
Common situations: Typo in MethodName vs. the name passed to task.Add during registration; service restarted without the plugin that registers the method; method removed/renamed in code while old task definitions still reference it; copying a task config between environments with different registered methods.
Related errors
- 参数错误:executionPlan 必须提供
- packageName 不能为空
- packageType 必须是 'package' 或 'plugin'
- packageType 和 packageInfo.template 必须保持一致
- 当 needCreatedPackage=true 时,packageInfo 不能为空
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/741ce7e8672bba08.
Report an issue: GitHub.