siyuan-note/siyuan · error

skill resource is not a regular file

Error message

skill resource is not a regular file: %s/%s

What it means

readSkillResource stats the resolved target and requires it to be a regular file. Directories, devices, sockets, and other special files are rejected, returning this error with the skill name and resource path.

Solutions

  1. Append the filename to the resource path so it points at a regular file
  2. Verify with os.Stat that the target is a regular file before calling
  3. Recreate the skill resource as a regular file if it was replaced by a special file

Example fix

// before
LoadSkill("my-skill", "reference") // directory
// after
LoadSkill("my-skill", "reference/guide.md") // regular file
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(filepath.Join(util.SkillsDir(), skill, filepath.FromSlash(resource)))
if err != nil || !fi.Mode().IsRegular() { /* not a readable file — abort */ }

Prevention

When it happens

Trigger: LoadSkill is called with a resource path that resolves to a directory (e.g. requesting the skill root or a subfolder) or another non-regular filesystem object.

Common situations: Passing a directory path instead of a file path (e.g. "docs" instead of "docs/index.md"); the resource being replaced by a FIFO or device node; skill folders assembled manually with unexpected entries.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at kernel/util/skill.go:372

func readSkillResource(skillDir, skillName, resource string) (string, error) {
	realRoot, err := filepath.EvalSymlinks(skillDir)
	if err != nil {
		return "", fmt.Errorf("skill not found: %s", skillName)
	}

	target := filepath.Join(realRoot, filepath.FromSlash(resource))
	realTarget, err := filepath.EvalSymlinks(target)
	if err != nil {
		return "", fmt.Errorf("skill resource not found: %s/%s", skillName, resource)
	}
	if realTarget != realRoot && !gulu.File.IsSubPath(realRoot, realTarget) {
		return "", fmt.Errorf("skill resource escapes skill directory: %s", resource)
	}

	info, err := os.Stat(realTarget)
	if err != nil || !info.Mode().IsRegular() {
		return "", fmt.Errorf("skill resource is not a regular file: %s/%s", skillName, resource)
	}
	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) {

View on GitHub (pinned to 9f775e8a12)