yamadashy/repomix · error · RepomixError
Failed to build full directory structure: ${error instanceof
Error message
Failed to build full directory structure: ${error instanceof Error ? error.message : String(error)} What it means
When full-tree mode applies (directoryStructure enabled and full tree needed), Repomix collects all directories/files via a search call; any exception there is rethrown as a RepomixError with the original error as `cause`. It signals that enumerating the complete directory tree for the output failed, not a user config value being invalid per se.
Source
Thrown at src/core/output/outputGenerate.ts:397
const allRepoFiles = Array.from(
new Set(
allFilesByRoot.flatMap((files, index) => {
const rootDir = rootDirs[index];
if (!rootDir) return [];
return files.map((filePath) => toOutputDisplayPath(rootDir, filePath, index));
}),
),
);
// Merge in any files that weren't part of the included files so they appear in the tree
const includedSet = new Set(allFilePaths);
const additionalFiles = allRepoFiles.filter((p) => !includedSet.has(p));
directoryPathsForTree = allDirectories;
// additionalFiles is already disjoint from allFilePaths (filtered above), so no dedup needed
filePathsForTree = allFilePaths.concat(additionalFiles);
} catch (error) {
throw new RepomixError(
`Failed to build full directory structure: ${error instanceof Error ? error.message : String(error)}`,
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();View on GitHub (pinned to f465ad9093)
Solutions
- Inspect `error.cause` (the original Error) for the real underlying filesystem failure.
- Fix filesystem access: check permissions on the directories being walked.
- Exclude problematic paths via `include`/`ignore` patterns in config.
- Retry on transient failures (network mount glitch); report a bug if it reproduces on a normal repo.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check walkability of the target directory import fs from 'node:fs/promises'; await fs.access(config.cwd, fs.constants.R_OK | fs.constants.X_OK);
Type guard
null
Try / catch
try {
await pack(...);
} catch (e) {
if (e instanceof RepomixError && e.message.startsWith('Failed to build full directory structure')) {
console.error('Underlying cause:', e.cause ?? e);
} else throw e;
} Prevention
- Ensure the process has read/execute permission on the packed directory tree.
- Avoid packing network mounts or paths with permission quirks.
- Use ignore patterns for known-problematic subtrees.
- Keep repomix updated to pick up filesystem-walk fixes.
When it happens
Trigger: buildOutputGeneratorContext's full-tree branch calls the file search and it throws — e.g. an underlying filesystem error while walking directories, or an unexpected failure in the searchFiles-based full-tree enumeration.
Common situations: Permission-denied on directories during traversal; filesystem errors on network mounts or broken symlinks; platform-specific path issues; a regression in the directory-listing code path.
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 search for empty directories: ${error instanceof E
- 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/50e8b45c3a2380d4.
Report an issue: GitHub.