{"record":{"id":"9757483dca2e1f8a","repo":"wavetermdev/waveterm","slug":"accessing-file-s-w","errorCode":null,"errorMessage":"accessing file %s: %w","messagePattern":"accessing file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-ai.go","lineNumber":110,"sourceCode":"\t\tvar mimeType string\n\t\tvar err error\n\n\t\tif filePath == \"-\" {\n\t\t\tif stdinUsed {\n\t\t\t\treturn fmt.Errorf(\"stdin (-) can only be used once\")\n\t\t\t}\n\t\t\tstdinUsed = true\n\n\t\t\tdata, err = io.ReadAll(os.Stdin)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"reading from stdin: %w\", err)\n\t\t\t}\n\t\t\tfileName = \"stdin\"\n\t\t\tmimeType = \"text/plain\"\n\t\t} else {\n\t\t\tfileInfo, err := os.Stat(filePath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"accessing file %s: %w\", filePath, err)\n\t\t\t}\n\t\t\tabsPath, err := filepath.Abs(filePath)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"getting absolute path for %s: %w\", filePath, err)\n\t\t\t}\n\n\t\t\tif fileInfo.IsDir() {\n\t\t\t\tresult, err := fileutil.ReadDir(filePath, 500)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"reading directory %s: %w\", filePath, err)\n\t\t\t\t}\n\t\t\t\tjsonData, err := json.Marshal(result)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"marshaling directory listing for %s: %w\", filePath, err)\n\t\t\t\t}\n\t\t\t\tdata = jsonData\n\t\t\t\tfileName = absPath\n\t\t\t\tmimeType = \"directory\"","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-ai.go#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\n$ wsh ai ./confg/app.yaml\n// error: accessing file ./confg/app.yaml: no such file or directory\n// after\n$ wsh ai ./config/app.yaml","handlingStrategy":"validation","validationCode":"for f in \"$@\"; do\n  [ -e \"$f\" ] || { echo \"not found: $f\" >&2; exit 1; }\ndone\nwsh ai \"$@\"","typeGuard":null,"tryCatchPattern":"if err := runAI(args); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && errors.Is(perr.Err, syscall.ENOENT) {\n        return fmt.Errorf(\"path %q does not exist (check spelling and cwd)\", perr.Path)\n    }\n    return err\n}","preventionTips":["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."],"tags":["filesystem","file-not-found","permissions","wsh"],"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"}