{"record":{"id":"e10b0f9939b7166a","repo":"yamadashy/repomix","slug":"failed-to-generate-xml-output-error-instanceof","errorCode":null,"errorMessage":"Failed to generate XML output: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Failed to generate XML output: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/output/outputGenerate.ts","lineNumber":168,"sourceCode":"            git_diff_staged: renderContext.gitDiffStaged,\n          }\n        : undefined,\n      git_logs: renderContext.gitLogEnabled\n        ? {\n            git_log_commit: renderContext.gitLogCommits?.map((commit) => ({\n              date: commit.date,\n              message: commit.message,\n              files: commit.files.map((file) => ({ '#text': file })),\n            })),\n          }\n        : undefined,\n      instruction: renderContext.instruction ? renderContext.instruction : undefined,\n    },\n  };\n  try {\n    return xmlBuilder.build(xmlDocument);\n  } catch (error) {\n    throw new RepomixError(\n      `Failed to generate XML output: ${error instanceof Error ? error.message : 'Unknown error'}`,\n      error instanceof Error ? { cause: error } : undefined,\n    );\n  }\n};\n\nconst generateParsableJsonOutput = async (renderContext: RenderContext): Promise<string> => {\n  const jsonDocument = {\n    ...(renderContext.fileSummaryEnabled && {\n      fileSummary: {\n        generationHeader: renderContext.generationHeader,\n        purpose: renderContext.summaryPurpose,\n        fileFormat: generateSummaryFileFormatJson(),\n        usageGuidelines: renderContext.summaryUsageGuidelines,\n        notes: renderContext.summaryNotes,\n      },\n    }),\n    ...(renderContext.headerText && {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/output/outputGenerate.ts#L150-L186","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrepomix --style xml  # fails on files with control chars\n// after\nrepomix --style xml --ignore \"**/*.bin,**/*.dat\"","handlingStrategy":"try-catch","validationCode":"const hasBadXmlChars = (s: string) => /[\\u0000-\\u0008\\u000B\\u000C\\u000E-\\u001F]/.test(s);\n// pre-scan packed files before generating:\nif (files.some(f => hasBadXmlChars(f.content))) console.warn('Files contain control characters');","typeGuard":"null","tryCatchPattern":"try {\n  const xml = await generateOutput({ ...config, output: { ...config.output, style: 'xml' } }, ctx);\n} catch (e) {\n  if (e instanceof RepomixError && e.message.startsWith('Failed to generate XML output')) {\n    console.error('XML build failed:', (e as { cause?: Error }).cause?.message);\n  }\n}","preventionTips":["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."],"tags":["xml","output","serialization"],"backgroundTag":"xml-serialization-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}