wavetermdev/waveterm · error
accessing file %s: %w
Error message
accessing file %s: %w
What it means
Wraps the error from os.Stat(filePath) for each non-stdin argument in `wsh ai`. It fires when the path cannot be stat'ed — typically it does not exist, or the user lacks permission on a parent directory. The wrapped error (e.g. *fs.PathError with ENOENT/EACCES) is preserved via %w.
Source
Thrown at cmd/wsh/cmd/wshcmd-ai.go:110
var mimeType string
var err error
if filePath == "-" {
if stdinUsed {
return fmt.Errorf("stdin (-) can only be used once")
}
stdinUsed = true
data, err = io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("reading from stdin: %w", err)
}
fileName = "stdin"
mimeType = "text/plain"
} else {
fileInfo, err := os.Stat(filePath)
if err != nil {
return fmt.Errorf("accessing file %s: %w", filePath, err)
}
absPath, err := filepath.Abs(filePath)
if err != nil {
return fmt.Errorf("getting absolute path for %s: %w", filePath, err)
}
if fileInfo.IsDir() {
result, err := fileutil.ReadDir(filePath, 500)
if err != nil {
return fmt.Errorf("reading directory %s: %w", filePath, err)
}
jsonData, err := json.Marshal(result)
if err != nil {
return fmt.Errorf("marshaling directory listing for %s: %w", filePath, err)
}
data = jsonData
fileName = absPath
mimeType = "directory"View on GitHub (pinned to a4447c1563)
Solutions
- Verify the path exists: run `ls -l <path>` (or `test -e <path> && echo ok`) in the same shell/cwd before invoking wsh ai.
- Check spelling and that relative paths resolve from the current working directory; use absolute paths in scripts.
- Fix permissions on the file or its parent directories (chmod/chown, or run with appropriate access).
- If it's a dangling symlink, point to the real target file.
Example fix
// before $ wsh ai ./confg/app.yaml // error: accessing file ./confg/app.yaml: no such file or directory // after $ wsh ai ./config/app.yaml
Defensive patterns
Strategy: validation
Validate before calling
for f in "$@"; do
[ -e "$f" ] || { echo "not found: $f" >&2; exit 1; }
done
wsh ai "$@" Try / catch
if err := runAI(args); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOENT) {
return fmt.Errorf("path %q does not exist (check spelling and cwd)", perr.Path)
}
return err
} Prevention
- Use absolute paths in scripts; verify cwd with `pwd` before relative-path invocations.
- Run `test -e <path>` (or ls) before attaching; clean stale entries from generated file lists.
- Check parent-directory execute permission when paths live in restricted dirs.
When it happens
Trigger: Any `wsh ai <path>` where path is missing, misspelled, a dangling symlink, or inaccessible due to directory permissions; also relative paths typed from the wrong working directory.
Common situations: Typo in filename, running wsh from a different cwd than expected in scripts, deleted files still referenced in a script, permission-restricted paths (e.g. /var/log/... as non-root).
Related errors
- reading directory %s: %w
- reading file %s: %w
- getting absolute path for %s: %w
- error creating listener at %v: %v
- file does not exist: %q
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/9757483dca2e1f8a.
Report an issue: GitHub.