{"record":{"id":"7c3a9c7e521246c6","repo":"affaan-m/ECC","slug":"enoent-pandoc-did-not-produce-a-docx-artifact","errorCode":"ENOENT","errorMessage":"pandoc did not produce a DOCX artifact","messagePattern":"pandoc did not produce a DOCX artifact","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/master-agreement-generator/scripts/build-agreement.js","lineNumber":192,"sourceCode":"    result.docxSkipped = true;\n    return result;\n  }\n  const canConvert = options.pandoc === undefined ? pandocAvailable() : options.pandoc;\n  if (!canConvert) {\n    throw new Error('DOCX required: pandoc unavailable; use --markdown-only for an explicit Markdown-only draft');\n  }\n  try {\n    const converted = spawnSync('pandoc', [mdPath, '-o', docxPath], CONVERTER_OPTIONS);\n    if (converted.error || converted.status !== 0) {\n      throw new Error('pandoc conversion failed; DOCX unavailable');\n    }\n    const artifact = fs.lstatSync(docxPath);\n    if (!artifact.isFile() || artifact.size === 0) {\n      throw new Error('pandoc did not produce a nonempty regular DOCX artifact');\n    }\n  } catch (error) {\n    fs.rmSync(docxPath, { force: true });\n    if (error.code === 'ENOENT') throw new Error('pandoc did not produce a DOCX artifact');\n    throw error;\n  }\n  result.docx = docxPath;\n  return result;\n}\n\nfunction main(argv) {\n  const [templatePath, specPath, outDir, ...flags] = argv;\n  if (!templatePath || !specPath || !outDir ||\n      flags.some(flag => !['--require-docx', '--markdown-only'].includes(flag)) ||\n      flags.length > 1) {\n    console.error('usage: build-agreement.js <template.md> <spec.json> <out_dir> [--require-docx | --markdown-only]');\n    return 2;\n  }\n  try {\n    const result = build(templatePath, specPath, outDir, { markdownOnly: flags.includes('--markdown-only') });\n    console.log(`wrote ${result.documentStatus} ${result.markdown}`);\n    if (result.docxSkipped) {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/master-agreement-generator/scripts/build-agreement.js#L174-L210","documentation":"This error is thrown by build-agreement.js after it invokes pandoc to generate a DOCX file. The script lstat's the expected output path inside a try block; if pandoc never created the file, lstatSync fails with ENOENT and the catch block replaces it with this clearer message. It signals the external pandoc tool failed or was never invoked successfully.","triggerScenarios":"Running the build-agreement script when pandoc is not installed, not on PATH, exits nonzero, or writes its output to a different path than docxPath (e.g. wrong --output directory or working directory).","commonSituations":"Fresh machines without pandoc installed; CI images missing the pandoc dependency; a pandoc version that rejects the input format; running from a directory where the relative docxPath does not resolve; pandoc failing on malformed Markdown front matter.","solutions":["Install pandoc (e.g. `brew install pandoc`, `apt install pandoc`, or `choco install pandoc`) and verify with `pandoc --version`.","Run the script again and check stderr for the underlying pandoc error (e.g. unrecognized format or read failure).","Confirm the output directory in the script's configuration exists and is writable so pandoc can create docxPath.","Pin a recent pandoc version in CI to avoid flag/format incompatibilities."],"exampleFix":"# before\n$ node build-agreement.js  # Error: pandoc did not produce a DOCX artifact\n# after\n$ pandoc --version         # ensure installed and on PATH\n$ node build-agreement.js  # docx generated","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process');\ntry { execSync('pandoc --version', { stdio: 'ignore' }); } catch { throw new Error('pandoc is required but not installed/on PATH'); }","typeGuard":"null","tryCatchPattern":"try {\n  await buildAgreement(opts);\n} catch (e) {\n  if (/pandoc did not produce/.test(e.message)) {\n    console.error('pandoc missing or failed; install pandoc and retry:', e.message);\n  } else throw e;\n}","preventionTips":["Check `pandoc --version` at script startup and fail fast with an install hint.","Add pandoc to CI image dependencies and lockfiles.","Use absolute output paths so pandoc writes where docxPath expects.","Log pandoc's stderr so the root cause is visible."],"tags":["pandoc","docx","build","external-tool"],"backgroundTag":"missing-dependency","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}