Tencent/WeKnora · error

failed to read file

Error message

failed to read file: %w

What it means

I/O wrapper in LoadSkillFile: os.ReadFile failed on the already-validated fullPath inside the skill directory. The path passed traversal checks, so this is a genuine filesystem problem — missing file, permissions, or TOCTOU removal — not a security rejection.

Solutions

  1. Confirm the file exists at the resolved path inside the skill directory
  2. Fix read permissions on the file and its parent directories
  3. Handle TOCTOU: re-list skill files if the directory changes during access
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/agent/skills/loader.go:234 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/41a567f8c6fe4c50. Report an issue: GitHub.

Appendix: source

Thrown at internal/agent/skills/loader.go:234

	fullPath := filepath.Join(skill.BasePath, cleanPath)

	// Verify the file is within the skill directory
	absSkillPath, err := filepath.Abs(skill.BasePath)
	if err != nil {
		return nil, err
	}
	absFilePath, err := filepath.Abs(fullPath)
	if err != nil {
		return nil, err
	}
	if !strings.HasPrefix(absFilePath, absSkillPath) {
		return nil, fmt.Errorf("file path outside skill directory: %s", relativePath)
	}

	// Read the file
	content, err := os.ReadFile(fullPath)
	if err != nil {
		return nil, fmt.Errorf("failed to read file: %w", err)
	}

	return &SkillFile{
		Name:     relativePath,
		Path:     absFilePath, // Use absolute path for sandbox execution
		Content:  string(content),
		IsScript: IsScript(relativePath),
	}, nil
}

// ListSkillFiles lists all files in a skill directory
func (l *Loader) ListSkillFiles(skillName string) ([]string, error) {
	skill, ok := l.discoveredSkills[skillName]
	if !ok {
		var err error
		skill, err = l.LoadSkillInstructions(skillName)
		if err != nil {
			return nil, fmt.Errorf("skill not found: %s", skillName)

View on GitHub (pinned to 988cbb0330)