{"record":{"id":"65b77438975940bc","repo":"plandex-ai/plandex","slug":"failed-to-read-file-s-v-65b774","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_shared.go","lineNumber":84,"sourceCode":"\t\t\ttotalMapSizeExceeded = true\n\t\t\tres.mapFilesSkippedAfterSizeLimit = append(res.mapFilesSkippedAfterSizeLimit, path)\n\t\t\tres.tokens = shared.GetBytesToTokensEstimate(size)\n\t\t} else if truncated {\n\t\t\tres.mapFilesTruncatedTooLarge = append(res.mapFilesTruncatedTooLarge, filePathWithSize{Path: path, Size: size})\n\t\t}\n\t}\n\n\tif totalMapSizeExceeded || !shared.HasFileMapSupport(path) || isImage {\n\t\tshaVal := sha256.Sum256([]byte(fmt.Sprintf(\"%d\", res.tokens)))\n\t\tres.shaVal = hex.EncodeToString(shaVal[:])\n\n\t\tres.mapContent = \"\"\n\t\tres.size = 0\n\t} else {\n\t\t// partial read for the map\n\t\tcontentRes, err := getMapFileContent(path)\n\t\tif err != nil {\n\t\t\treturn mapFileDetails{}, fmt.Errorf(\"failed to read file %s: %v\", path, err)\n\t\t}\n\n\t\tres.mapContent = contentRes.content\n\t\tres.shaVal = contentRes.shaVal\n\n\t\tif contentRes.truncated {\n\t\t\tres.mapFilesTruncatedTooLarge = append(res.mapFilesTruncatedTooLarge, filePathWithSize{Path: path, Size: shared.MaxContextMapSingleInputSize})\n\t\t\tres.size = shared.MaxContextMapSingleInputSize\n\t\t\tres.tokens = shared.GetBytesToTokensEstimate(shared.MaxContextMapSingleInputSize)\n\t\t} else {\n\t\t\t// do the actual token count if we didn't truncate\n\t\t\tres.tokens = shared.GetNumTokensEstimate(res.mapContent)\n\t\t}\n\t}\n\n\treturn res, nil\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/context_shared.go#L66-L102","documentation":"For non-truncated files, getMapFileDetails performs a partial read for the map via getMapFileContent and wraps any failure with this message. It means the file's content (and its sha) could not be read from disk, so the map entry for this file cannot be produced.","triggerScenarios":"getMapFileContent(path) returns an error during map building — permission-denied reads, file deleted mid-operation, or I/O errors on large/binary files.","commonSituations":"Files with restrictive permissions (root-owned, chmod 000); files removed by git checkout/clean while the command runs; encrypted or filesystem-corrupted files.","solutions":["Check the file exists and is readable by the current user (ls -l / chmod)","Restore deleted files (git checkout -- <file>) and re-run","Exclude unreadable files from the context paths"],"exampleFix":"// before\ncontentRes, err := getMapFileContent(path)\nif err != nil {\n    return mapFileDetails{}, fmt.Errorf(\"failed to read file %s: %v\", path, err)\n}\n// after\ncontentRes, err := getMapFileContent(path)\nif err != nil {\n    if os.IsPermission(err) {\n        fmt.Printf(\"skipping unreadable file %s\\n\", path)\n        return mapFileDetails{}, nil\n    }\n    return mapFileDetails{}, fmt.Errorf(\"failed to read file %s: %w\", path, err)\n}","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil {\n    return fmt.Errorf(\"file %s missing: %w\", path, err)\n}\nif !info.Mode().IsRegular() {\n    return fmt.Errorf(\"%s is not a regular file\", path)\n}\nf, err := os.Open(path)\nif err != nil {\n    return fmt.Errorf(\"file %s not readable: %w\", path, err)\n}\nf.Close()","typeGuard":"func isReadableRegularFile(path string) bool {\n    info, err := os.Stat(path)\n    if err != nil || !info.Mode().IsRegular() { return false }\n    f, err := os.Open(path)\n    if err != nil { return false }\n    f.Close()\n    return true\n}","tryCatchPattern":"contentRes, err := getMapFileContent(path)\nif err != nil {\n    if os.IsPermission(err) {\n        fmt.Printf(\"skipping unreadable file %s\\n\", path)\n    } else {\n        return fmt.Errorf(\"failed to read file %s: %w\", path, err)\n    }\n}","preventionTips":["Check file permissions before mapping large trees","Avoid mutating the working tree (git clean/checkout) while mapping","Exclude generated or encrypted files from context paths"],"tags":["filesystem","io","map"],"backgroundTag":"file-read-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}