flipped-aurora/gin-vue-admin · error

name不能为空

Error message

name不能为空

What it means

buildSkillContent serializes SkillMeta to YAML front matter for a SKILL.md file. It returns name不能为空 when meta.Name is the empty string, because a skill file without a name cannot be identified by the loader. The check runs before yaml.Marshal in the Save flow.

Source

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

			end = i
			break
		}
	}
	if end == -1 {
		return system.SkillMeta{}, clean, nil
	}
	yamlText := strings.Join(lines[1:end], "\n")
	body := strings.Join(lines[end+1:], "\n")
	var meta system.SkillMeta
	if err := yaml.Unmarshal([]byte(yamlText), &meta); err != nil {
		return system.SkillMeta{}, body, err
	}
	return meta, body, nil
}

func buildSkillContent(meta system.SkillMeta, markdown string) (string, error) {
	if meta.Name == "" {
		return "", errors.New("name不能为空")
	}
	data, err := yaml.Marshal(meta)
	if err != nil {
		return "", err
	}
	yamlText := strings.TrimRight(string(data), "\n")
	body := strings.TrimLeft(markdown, "\n")
	if body != "" {
		body = body + "\n"
	}
	return fmt.Sprintf("---\n%s\n---\n%s", yamlText, body), nil
}

func listFiles(dir string) []string {
	entries, err := os.ReadDir(dir)
	if err != nil {
		return []string{}
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Set meta.Name to a non-empty value before calling Save.
  2. Add required-field validation in the frontend form (name mandatory).
  3. If editing an existing skill, load its current meta first and keep the existing name.
  4. Server-side API callers: include "name" in the request payload.

Example fix

// before
meta := system.SkillMeta{Description: "demo"}
// after
meta := system.SkillMeta{Name: "my-skill", Description: "demo"}
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(meta.Name) == "" {
	return errors.New("skill meta.name is required before Save")
}

Type guard

func hasName(m system.SkillMeta) bool { return strings.TrimSpace(m.Name) != "" }

Try / catch

if _, err := svc.Save(req); err != nil {
	if strings.Contains(err.Error(), "name不能为空") {
		return fmt.Errorf("request must include a non-empty skill name")
	}
	return err
}

Prevention

When it happens

Trigger: Calling Save with a request whose meta.Name (or name field) is omitted or "", e.g. saving a skill created without completing the name field.

Common situations: Frontend form allows submit with empty name; API consumer posts JSON without the 'name' key; code that copies meta but forgets to set Name after a rename.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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