{"record":{"id":"b183945661719d7a","repo":"yamadashy/repomix","slug":"failed-to-read-file-filepath","errorCode":null,"errorMessage":"Failed to read file: ${filePath}","messagePattern":"Failed to read file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/core/file/fileRead.ts","lineNumber":148,"sourceCode":"      logger.debug(`Skipping binary file (content check): ${filePath}`);\n      return { content: null, skippedReason: 'binary-content' };\n    }\n\n    // Slow path: Detect encoding with jschardet for non-UTF-8 files (e.g., Shift-JIS, EUC-KR)\n    const encodingDeps = await getEncodingDeps();\n    const { encoding: detectedEncoding } = encodingDeps.jschardet.detect(buffer) ?? {};\n    const encoding =\n      detectedEncoding && encodingDeps.iconv.encodingExists(detectedEncoding) ? detectedEncoding : 'utf-8';\n    const content = encodingDeps.iconv.decode(buffer, encoding, { stripBOM: true });\n\n    if (content.includes('\\uFFFD')) {\n      logger.debug(`Skipping file due to encoding errors (detected: ${encoding}): ${filePath}`);\n      return { content: null, skippedReason: 'encoding-error' };\n    }\n\n    return { content };\n  } catch (error) {\n    logger.warn(`Failed to read file: ${filePath}`, error);\n    return { content: null, skippedReason: 'encoding-error' };\n  }\n};\n","sourceCodeStart":130,"sourceCodeEnd":152,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/file/fileRead.ts#L130-L152","documentation":"readRawFile logs this warning when any exception escapes the fs.readFile call (or encoding handling) in src/core/file/fileRead.ts. The function does not throw; it returns { content: null, skippedReason: 'encoding-error' } so the packing pipeline can skip the file gracefully. It covers permission errors, missing files, read races, and undecodable content.","triggerScenarios":"fs.readFile throws: file deleted between glob and read (TOCTOU race), EACCES/EPERM permissions, EISDIR, symlink loops, or a decode error in the encoding handling path.","commonSituations":"Reading a repo while a build deletes temp files; reading node_modules or system dirs without permission; reading binary/invalid-UTF8 files whose detected encoding fails; dangling symlinks caught by the glob.","solutions":["Check file permissions and that the file exists (ls -la <path>) and adjust the include/exclude patterns so unreadable paths are skipped.","If the file is binary or non-UTF8, add it to config.exclude or rely on the encoding-error skip; repomix intentionally skips it.","If it should never be read, tighten include globs; the warning is expected behavior and safe to ignore for skipped files.","For persistent failures on a valid file, run with debug logging to see the underlying error object logged by logger.warn."],"exampleFix":"// before: read fails with EACCES\n$ repomix --include src/secret.pem\n// after: exclude the unreadable file\n$ repomix --include \"src/**\" --exclude \"src/secret.pem\"","handlingStrategy":"fallback","validationCode":"const fs = require('fs');\nif (!fs.existsSync(p) || !fs.accessSync(p, fs.constants.R_OK)) throw new Error(`unreadable: ${p}`);","typeGuard":"const isReadable = (p) => { try { require('fs').accessSync(p, require('fs').constants.R_OK); return true; } catch { return false; } };","tryCatchPattern":"const { content, skippedReason } = await readRawFile(p);\nif (content === null) {\n  logger.warn(`skipped ${p}: ${skippedReason ?? 'read-failed'}`);\n}","preventionTips":["Exclude binary, symlinked, and permission-restricted paths via include/exclude globs.","Run as a user with read access to the target tree; avoid mixing users in CI checkouts.","Treat null content + skippedReason as normal control flow, not an exception."],"tags":["filesystem","file-read","permissions","graceful-skip"],"backgroundTag":"file-read-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}