yamadashy/repomix · warning
Failed to read file: ${filePath}
Error message
Failed to read file: ${filePath} What it means
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.
Source
Thrown at src/core/file/fileRead.ts:148
logger.debug(`Skipping binary file (content check): ${filePath}`);
return { content: null, skippedReason: 'binary-content' };
}
// Slow path: Detect encoding with jschardet for non-UTF-8 files (e.g., Shift-JIS, EUC-KR)
const encodingDeps = await getEncodingDeps();
const { encoding: detectedEncoding } = encodingDeps.jschardet.detect(buffer) ?? {};
const encoding =
detectedEncoding && encodingDeps.iconv.encodingExists(detectedEncoding) ? detectedEncoding : 'utf-8';
const content = encodingDeps.iconv.decode(buffer, encoding, { stripBOM: true });
if (content.includes('\uFFFD')) {
logger.debug(`Skipping file due to encoding errors (detected: ${encoding}): ${filePath}`);
return { content: null, skippedReason: 'encoding-error' };
}
return { content };
} catch (error) {
logger.warn(`Failed to read file: ${filePath}`, error);
return { content: null, skippedReason: 'encoding-error' };
}
};
View on GitHub (pinned to f465ad9093)
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.
Example fix
// before: read fails with EACCES $ repomix --include src/secret.pem // after: exclude the unreadable file $ repomix --include "src/**" --exclude "src/secret.pem"
Defensive patterns
Strategy: fallback
Validate before calling
const fs = require('fs');
if (!fs.existsSync(p) || !fs.accessSync(p, fs.constants.R_OK)) throw new Error(`unreadable: ${p}`); Type guard
const isReadable = (p) => { try { require('fs').accessSync(p, require('fs').constants.R_OK); return true; } catch { return false; } }; Try / catch
const { content, skippedReason } = await readRawFile(p);
if (content === null) {
logger.warn(`skipped ${p}: ${skippedReason ?? 'read-failed'}`);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to copy output file to ${targetPath}: Permission deni
- Could not read the remote repository's config (${configName}
- Permission denied while scanning directory. Please check fol
- Failed to write skill output to ${skillDir}: Permission deni
- Failed to copy output file: ${(error as Error).message}
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/b183945661719d7a.
Report an issue: GitHub.