{"record":{"id":"1b1649fbae060daf","repo":"wavetermdev/waveterm","slug":"cannot-open-dir-q-w","errorCode":null,"errorMessage":"cannot open dir %q: %w","messagePattern":"cannot open dir %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshrpc/wshremote/wshremote_file.go","lineNumber":250,"sourceCode":"\t\t\t\tif seen < data.Opts.Offset {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tif seen >= data.Opts.Offset+data.Opts.Limit {\n\t\t\t\t\treturn io.EOF\n\t\t\t\t}\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tif d.IsDir() {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tinnerFilesEntries = append(innerFilesEntries, d)\n\t\t\t\treturn nil\n\t\t\t})\n\t\t} else {\n\t\t\tinnerFilesEntries, err = os.ReadDir(path)\n\t\t\tif err != nil {\n\t\t\t\tch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](fmt.Errorf(\"cannot open dir %q: %w\", path, err))\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t\tvar fileInfoArr []*wshrpc.FileInfo\n\t\tfor _, innerFileEntry := range innerFilesEntries {\n\t\t\tif ctx.Err() != nil {\n\t\t\t\tch <- wshutil.RespErr[wshrpc.CommandRemoteListEntriesRtnData](ctx.Err())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tinnerFileInfoInt, err := innerFileEntry.Info()\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"cannot stat file %q: %v\\n\", innerFileEntry.Name(), err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tinnerFileInfo := statToFileInfo(filepath.Join(path, innerFileInfoInt.Name()), innerFileInfoInt, false)\n\t\t\tfileInfoArr = append(fileInfoArr, innerFileInfo)\n\t\t\tif len(fileInfoArr) >= wshrpc.DirChunkSize {\n\t\t\t\tresp := wshrpc.CommandRemoteListEntriesRtnData{FileInfo: fileInfoArr}","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshrpc/wshremote/wshremote_file.go#L232-L268","documentation":"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.","triggerScenarios":"Calling RemoteListEntriesCommand (Opts.All=false) with a path that does not exist, is a file, or lacks read permission.","commonSituations":"Typo in the directory path; listing a deleted directory; permission-restricted paths (e.g. /root); pointing at a file instead of a directory.","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."],"exampleFix":"// before\nch := wshclient.RemoteListEntriesCommand(ctx, wshrpc.CommandRemoteListEntriesData{Path: p}, nil)\n// after\nif _, err := wshclient.RemoteFileInfoCommand(ctx, p, nil); err != nil {\n    return fmt.Errorf(\"invalid dir %q: %w\", p, err)\n}\nch := wshclient.RemoteListEntriesCommand(ctx, wshrpc.CommandRemoteListEntriesData{Path: p}, nil)","handlingStrategy":"validation","validationCode":"info, err := wshclient.RemoteFileInfoCommand(ctx, dirPath, nil)\nif err != nil || info.DirType != \"dir\" {\n    return fmt.Errorf(\"not a readable directory: %s\", dirPath)\n}","typeGuard":null,"tryCatchPattern":"for item := range ch {\n    if item.Error != nil {\n        if errors.Is(item.Error, fs.ErrNotExist) { return ErrDirMissing }\n        return item.Error\n    }\n}","preventionTips":["Stat the directory before listing","Normalize/expand paths client-side","Run the server with permissions covering listed paths"],"tags":["filesystem","directory-listing","permissions","not-found"],"backgroundTag":"cannot-open-directory","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}