{"record":{"id":"0a8fb5db70632da4","repo":"plandex-ai/plandex","slug":"failed-to-read-file-s-v","errorCode":null,"errorMessage":"failed to read file %s: %v","messagePattern":"failed to read file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/context_auto_load.go","lineNumber":81,"sourceCode":"\t\t\t\tlog.Println(\"Skipping file\", path, \"because it's too large\", size)\n\t\t\t\tfilesSkippedTooLarge = append(filesSkippedTooLarge, filePathWithSize{Path: path, Size: size})\n\t\t\t\tmu.Unlock()\n\t\t\t\terrCh <- nil\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif totalSize+size > shared.MaxTotalContextSize {\n\t\t\t\tlog.Println(\"Skipping file\", path, \"because it would exceed the max context body size\", totalSize+size)\n\t\t\t\tfilesSkippedAfterSizeLimit = append(filesSkippedAfterSizeLimit, path)\n\t\t\t\tmu.Unlock()\n\t\t\t\terrCh <- nil\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttotalSize += size\n\t\t\tmu.Unlock()\n\n\t\t\tb, err := os.ReadFile(path)\n\t\t\tif err != nil {\n\t\t\t\terrCh <- fmt.Errorf(\"failed to read file %s: %v\", path, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar contextType shared.ContextType\n\t\t\tisImage := shared.IsImageFile(path)\n\t\t\tif isImage {\n\t\t\t\tcontextType = shared.ContextImageType\n\t\t\t} else {\n\t\t\t\tcontextType = shared.ContextFileType\n\t\t\t}\n\n\t\t\tvar imageDetail openai.ImageURLDetail\n\t\t\tif isImage {\n\t\t\t\timageDetail = openai.ImageURLDetailHigh\n\t\t\t}\n\n\t\t\tvar body string\n\t\t\tif isImage {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_auto_load.go#L63-L99","documentation":"In the per-file goroutine of AutoLoadContextFiles, os.ReadFile fails after the stat check succeeded, meaning the file became unreadable between stat and read or lacks read permission. The error is sent to errCh and surfaces to the caller as \"failed to load context\".","triggerScenarios":"os.ReadFile(path) errors: permission denied (file mode or ACL), the file was truncated/rotated/deleted mid-run (race), the \"file\" is a device/FIFO or /proc-like special file that cannot be read conventionally, or I/O errors (bad sector, network mount drop).","commonSituations":"Loading log files being actively rotated, reading files owned by another user (e.g. root-only configs), pointing context loading at virtual filesystems (/proc, /sys) or sockets, or NFS/network mounts flaking.","solutions":["Check the file's read permission bits (chmod or run as a user with access).","Exclude special files: verify mode.Type() == 0 (regular file) after stat, not just !IsDir().","Handle read races on rotated/deleted files by retrying once or skipping with a warning.","Ensure the file is closed/unlocked by the writer (e.g. editor swap files, active log rotation) before loading.","For network mounts, verify mount health and retry."],"exampleFix":"// before\nif fileInfo.IsDir() { ... }\nb, err := os.ReadFile(path)\n// after\nif !fileInfo.Mode().IsRegular() {\n    errCh <- nil // skip dirs, devices, fifos, sockets\n    return\n}\nb, err := os.ReadFile(path)\nif os.IsPermission(err) {\n    log.Printf(\"skipping unreadable file %s: %v\", path, err)\n    errCh <- nil\n    return\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil {\n    return fmt.Errorf(\"bad path %s: %w\", path, err)\n}\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file\", path)\n}\nif f, err := os.Open(path); err != nil {\n    return fmt.Errorf(\"%s not readable: %w\", path, err)\n} else { f.Close() }","typeGuard":null,"tryCatchPattern":"b, err := os.ReadFile(path)\nif err != nil {\n    switch {\n    case os.IsPermission(err):\n        log.Printf(\"skipping unreadable file %s\", path)\n        errCh <- nil\n    case os.IsNotExist(err):\n        log.Printf(\"file vanished during load: %s\", path)\n        errCh <- nil\n    default:\n        errCh <- fmt.Errorf(\"failed to read file %s: %v\", path, err)\n    }\n    return\n}","preventionTips":["Skip non-regular files (devices, FIFOs, sockets, /proc entries) after stat.","Check read permissions before batch-loading; run with an appropriate user.","Avoid loading actively rotated log files; snapshot or copy them first.","Retry reads once on transient I/O errors (network mounts)."],"tags":["filesystem","file-read","permissions","concurrency"],"backgroundTag":"file-read-permission-denied","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}