wavetermdev/waveterm · error
path must be absolute, got relative path: %s
Error message
path must be absolute, got relative path: %s
What it means
read_text_file only accepts absolute paths. After ExpandHomeDir resolves the filename, verifyReadTextFileInput checks filepath.IsAbs and rejects relative paths. This prevents reads that silently depend on the server process's working directory.
Source
Thrown at pkg/aiusechat/tools_readfile.go:212
return true, "Git credentials file"
}
return false, ""
}
func verifyReadTextFileInput(input any, toolUseData *uctypes.UIMessageDataToolUse) error {
params, err := parseReadTextFileInput(input)
if err != nil {
return err
}
expandedPath, err := wavebase.ExpandHomeDir(params.Filename)
if err != nil {
return fmt.Errorf("failed to expand path: %w", err)
}
if !filepath.IsAbs(expandedPath) {
return fmt.Errorf("path must be absolute, got relative path: %s", params.Filename)
}
if blocked, reason := isBlockedFile(expandedPath); blocked {
return fmt.Errorf("access denied: potentially sensitive file: %s", reason)
}
fileInfo, err := os.Stat(expandedPath)
if err != nil {
return fmt.Errorf("failed to stat file: %w", err)
}
if fileInfo.IsDir() {
return fmt.Errorf("path is a directory, cannot be read with the read_text_file tool. use the read_dir tool if available to read directories")
}
return nil
}
View on GitHub (pinned to a4447c1563)
Solutions
- Prefix the filename with "/" (or a Windows drive root).
- Use "~/..." so ExpandHomeDir produces an absolute path.
- Run filepath.IsAbs(expandedPath) in the caller before invoking the tool.
Example fix
// before
{"filename": "./config/settings.json"}
// after
{"filename": "/home/user/project/config/settings.json"} Defensive patterns
Strategy: validation
Validate before calling
const abs = require('path').isAbsolute(p) || p.startsWith('~');
if (!abs) throw new Error("use an absolute path for read_text_file"); Type guard
func isAbsAfterExpansion(p string) bool {
exp, err := wavebase.ExpandHomeDir(p)
return err == nil && filepath.IsAbs(exp)
} Try / catch
if err := verifyReadTextFileInput(params); err != nil {
if strings.Contains(err.Error(), "path must be absolute") {
// convert to absolute via filepath.Abs or cwd prefix, then retry
}
} Prevention
- Resolve relative paths against an explicit root before calling
- Never rely on the server process cwd
- On Windows include the drive letter in paths sent to the tool
When it happens
Trigger: Calling read_text_file with {"filename": "config.json"} or "./config.json" where expansion leaves the path relative.
Common situations: Agents working from a repo root assuming cwd-relative reads; symlinks or env drift making what was absolute relative; Windows paths passed without a drive letter.
Related errors
- Invalid command path: ${formatPath(path)}
- accessing file %s: %w
- getting absolute path for %s: %w
- reading directory %s: %w
- reading file %s: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/b663d1e0f49e748b.
Report an issue: GitHub.