wavetermdev/waveterm · error
cannot open dir %q: %w
Error message
cannot open dir %q: %w
What it means
RemoteListEntriesCommand failed to read the target directory with os.ReadDir for non-recursive listings. The error is wrapped with the directory path, so the cause (not-found, permission denied, not-a-directory) comes from the OS.
Source
Thrown at pkg/wshrpc/wshremote/wshremote_file.go:250
if seen < data.Opts.Offset {
return nil
}
if seen >= data.Opts.Offset+data.Opts.Limit {
return io.EOF
}
if err != nil {
return err
}
if d.IsDir() {
return nil
}
innerFilesEntries = append(innerFilesEntries, d)
return nil
})
} else {
innerFilesEntries, err = os.ReadDir(path)
if err != nil {
ch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf("cannot open dir %q: %w", path, err))
return
}
}
var fileInfoArr []*wshrpc.FileInfo
for _, innerFileEntry := range innerFilesEntries {
if ctx.Err() != nil {
ch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](ctx.Err())
return
}
innerFileInfoInt, err := innerFileEntry.Info()
if err != nil {
log.Printf("cannot stat file %q: %v\n", innerFileEntry.Name(), err)
continue
}
innerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false)
fileInfoArr = append(fileInfoArr, innerFileInfo)
if len(fileInfoArr) >= wshrpc.DirChunkSize {
resp := wshrpc.CommandRemoteListEntriesRtnData{FileInfo: fileInfoArr}View on GitHub (pinned to a4447c1563)
Solutions
- Check the wrapped error: fs.ErrNotExist means path missing; permission errors mean access issues.
- Verify the path exists and is a directory with RemoteFileInfoCommand before listing.
- Fix the path or run with sufficient permissions.
Example fix
// before
ch := wshclient.RemoteListEntriesCommand(ctx, wshrpc.CommandRemoteListEntriesData{Path: p}, nil)
// after
if _, err := wshclient.RemoteFileInfoCommand(ctx, p, nil); err != nil {
return fmt.Errorf("invalid dir %q: %w", p, err)
}
ch := wshclient.RemoteListEntriesCommand(ctx, wshrpc.CommandRemoteListEntriesData{Path: p}, nil) Defensive patterns
Strategy: validation
Validate before calling
info, err := wshclient.RemoteFileInfoCommand(ctx, dirPath, nil)
if err != nil || info.DirType != "dir" {
return fmt.Errorf("not a readable directory: %s", dirPath)
} Try / catch
for item := range ch {
if item.Error != nil {
if errors.Is(item.Error, fs.ErrNotExist) { return ErrDirMissing }
return item.Error
}
} Prevention
- Stat the directory before listing
- Normalize/expand paths client-side
- Run the server with permissions covering listed paths
When it happens
Trigger: Calling RemoteListEntriesCommand (Opts.All=false) with a path that does not exist, is a file, or lacks read permission.
Common situations: Typo in the directory path; listing a deleted directory; permission-restricted paths (e.g. /root); pointing at a file instead of a directory.
Related errors
- accessing file %s: %w
- reading directory %s: %w
- reading file %s: %w
- error creating listener at %v: %v
- getting file info: %w
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/1b1649fbae060daf.
Report an issue: GitHub.