yamadashy/repomix · error
Failed to filter files in directory ${rootDir}. Reason: ${er
Error message
Failed to filter files in directory ${rootDir}. Reason: ${error.message} What it means
Generic wrapper error from searchFiles: any non-PermissionError Error thrown while filtering files (globby scan, filtering, etc.) is caught, logged, and rethrown with the root directory and original message attached. PermissionError instances are rethrown unchanged.
Source
Thrown at src/core/file/fileSearch.ts:348
logger.debug(
`[result] Total files: ${confinedFilePaths.length}, empty directories: ${confinedEmptyDirPaths.length}`,
);
logger.trace(`Filtered ${confinedFilePaths.length} files`);
return {
filePaths: sortPaths(confinedFilePaths),
emptyDirPaths: sortPaths(confinedEmptyDirPaths),
};
} catch (error: unknown) {
// Re-throw PermissionError as is
if (error instanceof PermissionError) {
throw error;
}
if (error instanceof Error) {
logger.error('Error filtering files:', error.message);
throw new Error(`Failed to filter files in directory ${rootDir}. Reason: ${error.message}`);
}
logger.error('An unexpected error occurred:', error);
throw new Error('An unexpected error occurred while filtering files.');
}
};
export const parseIgnoreContent = (content: string): string[] => {
if (!content) return [];
return content.split('\n').reduce<string[]>((acc, line) => {
const trimmedLine = line.trim();
if (trimmedLine && !trimmedLine.startsWith('#')) {
acc.push(trimmedLine);
}
return acc;
}, []);
};View on GitHub (pinned to f465ad9093)
Solutions
- Read the 'Reason:' suffix in the message — it contains the underlying error — and fix that root cause.
- Check your repomix.json include/ignore glob patterns for typos or invalid syntax.
- If the reason is EMFILE, raise the file descriptor limit (ulimit -n) or reduce the size of the scanned tree.
- Retry after fixing; if the underlying cause is a permission issue, address it per the PermissionError guidance.
Example fix
// before: invalid include pattern in repomix.config.json "include": ["src/[!"] // after "include": ["src/**/*"]
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate glob patterns before packing
const patterns = config.include.concat(config.ignore);
for (const p of patterns) {
if (p.includes('[') && !/^\[!?.*\]$/.test(p.split('/').find(s => s.startsWith('[')) ?? '')) {
throw new Error(`Suspicious glob pattern: ${p}`);
}
} Type guard
const isPermissionError = (e: unknown): e is Error & { name: 'PermissionError' } =>
e instanceof Error && e.name === 'PermissionError'; Try / catch
try {
await repomix.pack({ input: { rootDir } });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Failed to filter files in directory')) {
console.error('Underlying cause:', e.message.split('Reason: ')[1]);
} else throw e;
} Prevention
- Validate include/ignore glob patterns (e.g. with minimatch) before running.
- Watch file descriptor limits when packing very large trees (ulimit -n).
- Keep globby and filesystem-related dependencies up to date.
- Read the 'Reason:' part of the message — it names the true root cause.
When it happens
Trigger: Any Error thrown inside searchFiles' try block other than PermissionError — e.g. malformed file patterns, globby internal failures, or filesystem errors with codes other than EPERM/EACCES.
Common situations: Invalid glob patterns in repomix config, unusual filesystem errors (EMFILE too many open files, EIO), or plugin/config issues producing bad include patterns.
Related errors
- Permission denied while scanning directory. Please check fol
- An unexpected error occurred while filtering files.
- Failed to copy output file to ${targetPath}: Permission deni
- Failed to copy output file: ${(error as Error).message}
- Refusing to trust ${configName}: the remote repository's con
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/8552f4e3d1d9242d.
Report an issue: GitHub.