yamadashy/repomix · error · RepomixError
Failed to search for empty directories: ${error instanceof E
Error message
Failed to search for empty directories: ${error instanceof Error ? error.message : String(error)} What it means
When `directoryStructure` and `includeEmptyDirectories` are enabled, Repomix searches for empty directories per root dir and merges their display paths; any exception in that search is rethrown as a RepomixError with the original error as `cause`. It means the empty-directory scan for the tree output failed.
Source
Thrown at src/core/output/outputGenerate.ts:417
error instanceof Error ? { cause: error } : undefined,
);
}
} else if (config.output.directoryStructure && config.output.includeEmptyDirectories) {
// Reuse pre-computed emptyDirPaths from the initial searchFiles call when available,
// avoiding a redundant full directory scan.
if (emptyDirPaths) {
directoryPathsForTree = emptyDirPaths;
} else {
try {
const results = await Promise.all(rootDirs.map((rootDir) => deps.searchFiles(rootDir, config)));
const merged = results.flatMap((result, index) => {
const rootDir = rootDirs[index];
if (!rootDir) return [];
return result.emptyDirPaths.map((emptyDirPath) => toOutputDisplayPath(rootDir, emptyDirPath, index));
});
directoryPathsForTree = [...new Set(merged)].sort();
} catch (error) {
throw new RepomixError(
`Failed to search for empty directories: ${error instanceof Error ? error.message : String(error)}`,
error instanceof Error ? { cause: error } : undefined,
);
}
}
}
// Generate tree string - use multi-root format if filePathsByRoot is provided
// generateTreeStringWithRoots handles single root case internally
let treeString: string;
if (filePathsByRoot) {
treeString = generateTreeStringWithRoots(filePathsByRoot, directoryPathsForTree);
} else {
// Fallback for when root info is not available
treeString = generateTreeString(filePathsForTree, directoryPathsForTree);
}
return {View on GitHub (pinned to f465ad9093)
Solutions
- Inspect `error.cause` for the underlying scan failure.
- Restore read permissions on directories being scanned.
- Disable `includeEmptyDirectories` if the empty-dir tree is not essential.
- Re-run to rule out a transient race (directory deleted during scan).
Example fix
// before (repomix.json) "directoryStructure": true, "includeEmptyDirectories": true // after (workaround when scan fails on unreadable dirs) "directoryStructure": true, "includeEmptyDirectories": false
Defensive patterns
Strategy: fallback
Validate before calling
// Check tree readability before enabling empty-dir scan import fs from 'node:fs/promises'; await fs.access(config.cwd, fs.constants.R_OK);
Type guard
null
Try / catch
try {
await pack({ ...config, output: { ...config.output, includeEmptyDirectories: true } });
} catch (e) {
if (e instanceof RepomixError && e.message.startsWith('Failed to search for empty directories')) {
console.error('empty-dir scan failed:', e.cause ?? e);
await pack({ ...config, output: { ...config.output, includeEmptyDirectories: false } });
} else throw e;
} Prevention
- Only enable includeEmptyDirectories when the tree display actually needs it.
- Fix permissions on scanned directories beforehand.
- Don't mutate the directory tree while packing is running.
- Inspect e.cause for the underlying scan error before retrying.
When it happens
Trigger: Enabling `output.includeEmptyDirectories: true` with `directoryStructure: true` and the empty-dir search call (executed per rootDir, mapped through toOutputDisplayPath) throws — typically an underlying filesystem walk error.
Common situations: Running against a directory tree with unreadable subdirectories; errors on exotic filesystems (Windows reserved names, network shares); race where a directory disappears mid-scan.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- Failed to build full directory structure: ${error instanceof
- 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
- Refusing to trust ${configName}: it resolves outside the clo
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/5c08174428df5a8e.
Report an issue: GitHub.