{"record":{"id":"c3a93e2355ac77ad","repo":"wavetermdev/waveterm","slug":"failed-to-stat-path-w-c3a93e","errorCode":null,"errorMessage":"failed to stat path: %w","messagePattern":"failed to stat path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/fileutil/readdir.go","lineNumber":46,"sourceCode":"type ReadDirResult struct {\n\tPath         string        `json:\"path\"`\n\tAbsolutePath string        `json:\"absolute_path\"`\n\tParentDir    string        `json:\"parent_dir,omitempty\"`\n\tEntries      []DirEntryOut `json:\"entries\"`\n\tEntryCount   int           `json:\"entry_count\"`\n\tTotalEntries int           `json:\"total_entries\"`\n\tTruncated    bool          `json:\"truncated,omitempty\"`\n}\n\nfunc ReadDir(path string, maxEntries int) (*ReadDirResult, error) {\n\texpandedPath, err := wavebase.ExpandHomeDir(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to expand path: %w\", err)\n\t}\n\n\tfileInfo, err := os.Stat(expandedPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to stat path: %w\", err)\n\t}\n\n\tif !fileInfo.IsDir() {\n\t\treturn nil, fmt.Errorf(\"path is not a directory\")\n\t}\n\n\tentries, err := os.ReadDir(expandedPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read directory: %w\", err)\n\t}\n\n\ttotalEntries := len(entries)\n\n\tisDirMap := make(map[string]bool)\n\tsymlinkCount := 0\n\tfor _, entry := range entries {\n\t\tname := entry.Name()\n\t\tif entry.Type()&fs.ModeSymlink != 0 {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/fileutil/readdir.go#L28-L64","documentation":"After expanding the path, ReadDir calls os.Stat; any stat failure (most commonly a nonexistent path) is wrapped as 'failed to stat path'. The OS-level cause (ENOENT, EACCES, ENOTDIR) is preserved via %w. ReadDir requires an existing, statable path before it can proceed.","triggerScenarios":"Calling ReadDir with a path that does not exist, is misspelled, sits under a non-directory component, or is unreadable due to permissions on a parent directory.","commonSituations":"Typo in the directory name; relative path resolved against an unexpected working directory; directory removed by a build/clean step; sandboxed agent lacking permission to traverse a parent dir; case-sensitive filesystem mismatch (LogS vs logs on Linux).","solutions":["Verify the path exists: `ls -ld <path>`; fix typos and casing.","Print or log the absolute working directory and make the path absolute to rule out cwd surprises.","Check execute (x) permission on every parent directory of the path.","Create the directory first if it is expected to exist (`os.MkdirAll`)."],"exampleFix":"// before\nfileutil.ReadDir(\"./out/dist\", 100) // run from wrong cwd\n// after\nfileutil.ReadDir(\"/home/user/project/out/dist\", 100)","handlingStrategy":"validation","validationCode":"abs, err := filepath.Abs(path)\nif err != nil { return err }\nif _, err := os.Stat(abs); err != nil {\n\treturn fmt.Errorf(\"path %s does not exist: %w\", abs, err)\n}","typeGuard":"func pathExists(path string) bool {\n\t_, err := os.Stat(path)\n\treturn err == nil\n}","tryCatchPattern":"res, err := fileutil.ReadDir(path, max)\nif err != nil {\n\tif errors.Is(errors.Unwrap(err), fs.ErrNotExist) {\n\t\t// create, prompt, or skip\n\t}\n\treturn err\n}","preventionTips":["Convert relative paths to absolute early, anchored to a known base directory.","Log resolved absolute paths to catch cwd assumptions.","On Linux, remember path casing is significant."],"tags":["filesystem","go","path","not-found"],"backgroundTag":"no-such-file-or-directory","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}