flipped-aurora/gin-vue-admin · error

脚本类型不支持

Error message

脚本类型不支持

What it means

After buildScriptFileName normalizes the requested script type, an unknown type leaves lang empty and CreateScript returns "脚本类型不支持". Only "py/python", "js/javascript/script", and "sh/shell/bash" are accepted (case-insensitive).

Source

Thrown at server/service/system/sys_skills.go:276

	}

	if err = zw.Close(); err != nil {
		return "", nil, err
	}

	return req.Skill + ".zip", buf.Bytes(), nil
}

func (s *SkillsService) CreateScript(_ context.Context, req request.SkillScriptCreateRequest) (string, string, error) {
	if !isSafeName(req.Skill) {
		return "", "", errors.New("技能名称不合法")
	}
	fileName, lang, err := buildScriptFileName(req.FileName, req.ScriptType)
	if err != nil {
		return "", "", err
	}
	if lang == "" {
		return "", "", errors.New("脚本类型不支持")
	}
	skillDir, err := s.ensureSkillDir(req.Tool, req.Skill)
	if err != nil {
		return "", "", err
	}
	filePath := filepath.Join(skillDir, "scripts", fileName)
	if _, err := os.Stat(filePath); err == nil {
		return "", "", errors.New("脚本已存在")
	}
	if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
		return "", "", err
	}
	content := scriptTemplate(lang)
	if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
		return "", "", err
	}
	return fileName, content, nil
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Use one of: py/python, js/javascript/script, sh/shell/bash (case-insensitive)
  2. For TypeScript or other languages, create the file manually via SaveScript or add a case to buildScriptFileName
  3. Fix the frontend select options to match the backend's accepted values

Example fix

// before
{ "fileName": "build.ts", "scriptType": "typescript" }
// after
{ "fileName": "build", "scriptType": "js" }  // or use SaveScript to write a .ts file manually
Defensive patterns

Strategy: validation

Validate before calling

var allowed = map[string]bool{"py": true, "python": true, "js": true, "javascript": true, "script": true, "sh": true, "shell": true, "bash": true}
if !allowed[strings.ToLower(req.ScriptType)] { /* reject or map before calling */ }

Try / catch

if err := svc.CreateScript(ctx, req); err != nil {
    if err.Error() == "脚本类型不支持" {
        return fmt.Errorf("脚本类型仅支持 py/js/sh: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling CreateScript with ScriptType values like "ts", "typescript", "rb", "go", "powershell", or an empty string.

Common situations: Frontend dropdown out of sync with backend enum; user assuming TypeScript is supported; API consumers guessing the type string instead of using the allowed set.

Related errors


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