flipped-aurora/gin-vue-admin · error

executorType 必须为 %s 或 %s

Error message

executorType 必须为 %s 或 %s

What it means

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.

Source

Thrown at server/service/system/sys_timed_task.go:72

		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)
	}
	return nil
}

// checkNameUnique 软删除下不建 DB 唯一索引, 由服务层保证活跃行内唯一
func (s *TimedTaskService) checkNameUnique(ctx context.Context, name string, excludeID uint) error {
	var count int64
	db := global.GVA_DB.WithContext(ctx).Model(&system.SysTimedTask{}).Where("name = ?", name)
	if excludeID > 0 {
		db = db.Where("id <> ?", excludeID)
	}
	if err := db.Count(&count).Error; err != nil {
		return err
	}
	if count > 0 {
		return fmt.Errorf("任务名 %s 已存在", name)
	}
	return nil

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Set executorType to the constant system.TimedTaskExecutorMethod (method-based task) or system.TimedTaskExecutorHTTP (HTTP-based task) exactly as defined in the system model package
  2. Inspect the model constants (system.TimedTaskExecutorMethod / TimedTaskExecutorHTTP) and align the client payload's field name and value type
  3. If creating via the admin UI, re-select the executor type so the bound enum value is sent, not a label string

Example fix

// before
{"name":"sync","spec":"0 5 * * *","executorType":1}
// after
{"name":"sync","spec":"0 5 * * *","executorType":"method"}
Defensive patterns

Strategy: validation

Validate before calling

var validExecutors = map[string]bool{"method": true, "http": true} // align with system.TimedTaskExecutorMethod/HTTP
if !validExecutors[task.ExecutorType] {
    return fmt.Errorf("executorType must be one of: method, http")
}
// then call CreateTimedTask / UpdateTimedTask

Type guard

func isValidExecutorType(t string) bool {
    return t == system.TimedTaskExecutorMethod || t == system.TimedTaskExecutorHTTP
}

Prevention

When it happens

Trigger: 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}.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/3d6edcb881d59137. Report an issue: GitHub.