yamadashy/repomix · error · RepomixError
Failed to generate XML output: ${error instanceof Error ? er
Error message
Failed to generate XML output: ${error instanceof Error ? error.message : 'Unknown error'} What it means
XML generation via the fast-xml-parser builder failed while serializing the prepared xmlDocument. Repomix wraps the builder's exception in a RepomixError with the original message preserved as the cause.
Source
Thrown at src/core/output/outputGenerate.ts:168
git_diff_staged: renderContext.gitDiffStaged,
}
: undefined,
git_logs: renderContext.gitLogEnabled
? {
git_log_commit: renderContext.gitLogCommits?.map((commit) => ({
date: commit.date,
message: commit.message,
files: commit.files.map((file) => ({ '#text': file })),
})),
}
: undefined,
instruction: renderContext.instruction ? renderContext.instruction : undefined,
},
};
try {
return xmlBuilder.build(xmlDocument);
} catch (error) {
throw new RepomixError(
`Failed to generate XML output: ${error instanceof Error ? error.message : 'Unknown error'}`,
error instanceof Error ? { cause: error } : undefined,
);
}
};
const generateParsableJsonOutput = async (renderContext: RenderContext): Promise<string> => {
const jsonDocument = {
...(renderContext.fileSummaryEnabled && {
fileSummary: {
generationHeader: renderContext.generationHeader,
purpose: renderContext.summaryPurpose,
fileFormat: generateSummaryFileFormatJson(),
usageGuidelines: renderContext.summaryUsageGuidelines,
notes: renderContext.summaryNotes,
},
}),
...(renderContext.headerText && {View on GitHub (pinned to f465ad9093)
Solutions
- Read `error.cause` for the exact builder message.
- Exclude problematic files with --ignore patterns (binary/control-character files).
- Upgrade repomix — builder-level serialization bugs are often fixed upstream.
- Validate that file contents passed to the renderer are strings with valid XML characters.
Example fix
// before repomix --style xml # fails on files with control chars // after repomix --style xml --ignore "**/*.bin,**/*.dat"
Defensive patterns
Strategy: try-catch
Validate before calling
const hasBadXmlChars = (s: string) => /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(s);
// pre-scan packed files before generating:
if (files.some(f => hasBadXmlChars(f.content))) console.warn('Files contain control characters'); Type guard
null
Try / catch
try {
const xml = await generateOutput({ ...config, output: { ...config.output, style: 'xml' } }, ctx);
} catch (e) {
if (e instanceof RepomixError && e.message.startsWith('Failed to generate XML output')) {
console.error('XML build failed:', (e as { cause?: Error }).cause?.message);
}
} Prevention
- Ignore binary/control-character files with --ignore.
- Sanitize file contents to valid XML characters in preprocessing.
- Keep repomix and fast-xml-parser versions current.
- Inspect error.cause for the exact builder failure.
When it happens
Trigger: generateParsableXmlOutput(renderContext) calls xmlBuilder.build and the underlying builder throws — typically due to unencodable characters in file content/metadata, invalid XML attribute values (e.g. non-string scalar types), or a builder misconfiguration.
Common situations: Repositories containing binary or control-character-laden files whose content sneaks into XML attributes; unusual filenames with invalid XML characters; memory exhaustion on huge outputs.
Related errors
- Failed to generate JSON output: ${error instanceof Error ? e
- Unsupported output style for handlebars template: ${style}
- Output size exceeds JavaScript string limit. The repository
- Failed to compile template: ${error instanceof Error ? error
- Unsupported output style: ${config.output.style}
AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29).
Data as JSON: /api/errors/e10b0f9939b7166a.
Report an issue: GitHub.