siyuan-note/siyuan · error

skill resource is not valid UTF-8

Error message

skill resource is not valid UTF-8: %s/%s

What it means

Thrown by readSkillResource when the bytes read from the skill resource file are not valid UTF-8. Skill resources are served as text (LoadSkill feeds them to the AI runtime), so binary or non-UTF-8-encoded files under the skill directory are rejected with skillName/resource identifying the offending file; replace it with UTF-8 content.

Solutions

  1. Convert the resource file to UTF-8 (iconv -f GBK -t UTF-8 file.md > file.utf8.md, or re-save with editor encoding set to UTF-8)
  2. Remove binary assets from text resource paths and reference them appropriately outside the skill-resource API
  3. Ensure editors/tools write UTF-8 without legacy encodings when editing skill files

Example fix

// before
iconv -f GBK -t UTF-8 old.md > converted.md   # keep original name
mv converted.md reference.md
// after
LoadSkill("my-skill", "reference.md") // now valid UTF-8
Defensive patterns

Strategy: validation

Validate before calling

b, err := os.ReadFile(p)
if err == nil && !utf8.Valid(b) { /* convert to UTF-8 before loading */ }

Prevention

When it happens

Trigger: LoadSkill is called on a resource file encoded in another charset (GBK, Shift-JIS, Latin-1, UTF-16) or containing binary data.

Common situations: Skill documents authored on Windows in a legacy codepage; files saved by an editor with wrong encoding; accidentally placed binary assets (images, zip) referenced as text resources.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/19c8f5150a7fde7c. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/skill.go:391

	}
	if info.Size() > maxSkillResourceBytes {
		return "", fmt.Errorf("skill resource exceeds the %d byte limit: %s/%s", maxSkillResourceBytes, skillName, resource)
	}

	file, err := os.Open(realTarget)
	if err != nil {
		return "", fmt.Errorf("skill resource not found: %s/%s", skillName, resource)
	}
	defer file.Close()
	data, err := io.ReadAll(io.LimitReader(file, maxSkillResourceBytes+1))
	if err != nil {
		return "", fmt.Errorf("skill resource read failed: %s/%s", skillName, resource)
	}
	if len(data) > maxSkillResourceBytes {
		return "", fmt.Errorf("skill resource exceeds the %d byte limit: %s/%s", maxSkillResourceBytes, skillName, resource)
	}
	if !utf8.Valid(data) {
		return "", fmt.Errorf("skill resource is not valid UTF-8: %s/%s", skillName, resource)
	}
	return string(data), nil
}

func validateSkillName(name string) error {
	if name == "" || name == "." || name == ".." {
		return fmt.Errorf("invalid skill name: %s", name)
	}
	if strings.ContainsAny(name, `/\`) {
		return fmt.Errorf("invalid skill name: %s", name)
	}
	dir := SkillsDir()
	abs := filepath.Join(dir, name)
	if !gulu.File.IsSubPath(dir, abs) {
		return fmt.Errorf("invalid skill name: %s", name)
	}
	return nil
}

View on GitHub (pinned to 9f775e8a12)