{"record":{"id":"3d6edcb881d59137","repo":"flipped-aurora/gin-vue-admin","slug":"executortype-s-s","errorCode":null,"errorMessage":"executorType 必须为 %s 或 %s","messagePattern":"executorType 必须为 (.+?) 或 (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_timed_task.go","lineNumber":72,"sourceCode":"\t\tif _, ok := task.Get(t.MethodName); !ok {\n\t\t\treturn fmt.Errorf(\"方法 %s 未注册\", t.MethodName)\n\t\t}\n\t\tif len(t.Params) > 0 && !json.Valid(t.Params) {\n\t\t\treturn errors.New(\"params 必须是合法 JSON\")\n\t\t}\n\tcase system.TimedTaskExecutorHTTP:\n\t\tu, err := url.Parse(t.HttpUrl)\n\t\tif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") || u.Host == \"\" {\n\t\t\treturn errors.New(\"httpUrl 必须是合法的 http/https 地址\")\n\t\t}\n\t\tif len(t.HttpHeader) > 0 {\n\t\t\tvar hdr map[string]string\n\t\t\tif err := json.Unmarshal(t.HttpHeader, &hdr); err != nil {\n\t\t\t\treturn errors.New(`httpHeader 必须是 {\"Key\":\"Value\"} 形式的 JSON 对象`)\n\t\t\t}\n\t\t}\n\tdefault:\n\t\treturn fmt.Errorf(\"executorType 必须为 %s 或 %s\", system.TimedTaskExecutorMethod, system.TimedTaskExecutorHTTP)\n\t}\n\treturn nil\n}\n\n// checkNameUnique 软删除下不建 DB 唯一索引, 由服务层保证活跃行内唯一\nfunc (s *TimedTaskService) checkNameUnique(ctx context.Context, name string, excludeID uint) error {\n\tvar count int64\n\tdb := global.GVA_DB.WithContext(ctx).Model(&system.SysTimedTask{}).Where(\"name = ?\", name)\n\tif excludeID > 0 {\n\t\tdb = db.Where(\"id <> ?\", excludeID)\n\t}\n\tif err := db.Count(&count).Error; err != nil {\n\t\treturn err\n\t}\n\tif count > 0 {\n\t\treturn fmt.Errorf(\"任务名 %s 已存在\", name)\n\t}\n\treturn nil","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_timed_task.go#L54-L90","documentation":"validateTask falls through to a default branch when the task's executorType matches neither the registered 'method' executor nor the 'http' executor. The service only supports these two executor types, so any other value (empty string, typo, arbitrary enum) is rejected with this formatted error naming the two allowed values.","triggerScenarios":"Calling CreateTimedTask or UpdateTimedTask (via the timed-task admin API) with executorType set to an empty value, a misspelled constant, or a numeric/string value outside {TimedTaskExecutorMethod, TimedTaskExecutorHTTP}.","commonSituations":"Frontend sends executorType as a number while the backend expects the string constant; API consumers omitting executorType entirely; importing tasks from an older schema that used different executor names; hand-crafted JSON payloads to the task API.","solutions":["Set executorType to the constant system.TimedTaskExecutorMethod (method-based task) or system.TimedTaskExecutorHTTP (HTTP-based task) exactly as defined in the system model package","Inspect the model constants (system.TimedTaskExecutorMethod / TimedTaskExecutorHTTP) and align the client payload's field name and value type","If creating via the admin UI, re-select the executor type so the bound enum value is sent, not a label string"],"exampleFix":"// before\n{\"name\":\"sync\",\"spec\":\"0 5 * * *\",\"executorType\":1}\n// after\n{\"name\":\"sync\",\"spec\":\"0 5 * * *\",\"executorType\":\"method\"}","handlingStrategy":"validation","validationCode":"var validExecutors = map[string]bool{\"method\": true, \"http\": true} // align with system.TimedTaskExecutorMethod/HTTP\nif !validExecutors[task.ExecutorType] {\n    return fmt.Errorf(\"executorType must be one of: method, http\")\n}\n// then call CreateTimedTask / UpdateTimedTask","typeGuard":"func isValidExecutorType(t string) bool {\n    return t == system.TimedTaskExecutorMethod || t == system.TimedTaskExecutorHTTP\n}","tryCatchPattern":null,"preventionTips":["Share the enum constants between frontend and backend (generated constants or shared spec) instead of hardcoding values","Validate payload shape in the API layer with a schema validator before reaching the service","Add a frontend dropdown bound to the exact constant values, never free-text"],"tags":["validation","timed-task","go","config"],"backgroundTag":"invalid-enum-value","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}