{"record":{"id":"4ac89f0afee1c59e","repo":"tinyhumansai/openhuman","slug":"generated-block-end-marker-must-come-after-the-beg","errorCode":null,"errorMessage":"generated-block END marker must come after the BEGIN marker","messagePattern":"generated-block END marker must come after the BEGIN marker","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/generate-architecture-docs.mjs","lineNumber":126,"sourceCode":" * marker lines (markers preserved). Returns the updated document text.\n *\n * @param {string} docSource\n * @param {string[]} bodyLines\n * @returns {string}\n * @throws if the markers are missing or out of order\n */\nexport function spliceGeneratedBlock(docSource, bodyLines) {\n  const lines = docSource.split('\\n');\n  const beginIdx = lines.findIndex(l => l.includes(BLOCK_BEGIN_TOKEN));\n  const endIdx = lines.findIndex(l => l.includes(BLOCK_END_TOKEN));\n  if (beginIdx === -1 || endIdx === -1) {\n    throw new Error(\n      `generated-block markers not found in ${FRONTEND_DOC}; expected HTML comments ` +\n        `containing \"${BLOCK_BEGIN_TOKEN}\" and \"${BLOCK_END_TOKEN}\"`\n    );\n  }\n  if (endIdx <= beginIdx) {\n    throw new Error('generated-block END marker must come after the BEGIN marker');\n  }\n  const next = [...lines.slice(0, beginIdx + 1), ...bodyLines, ...lines.slice(endIdx)];\n  return next.join('\\n');\n}\n\n/**\n * Compute the desired doc content from the current sources.\n * @returns {{ updated: string, current: string }}\n */\nexport function computeFrontendDoc() {\n  const providers = parseProviderChain(readFileSync(APP_TSX, 'utf8'));\n  const current = readFileSync(FRONTEND_DOC, 'utf8');\n  const updated = spliceGeneratedBlock(current, renderProviderChainBody(providers));\n  return { updated, current };\n}\n\nfunction main() {\n  const check = process.argv.includes('--check');","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/a221052e0df5b1f7598fceba7329fd1af95d6699/scripts/generate-architecture-docs.mjs#L108-L144","documentation":"spliceGeneratedBlock() found both marker lines in gitbooks/developing/architecture/frontend.md but the first line containing 'END GENERATED: provider-chain' appears at or before the first line containing 'BEGIN GENERATED: provider-chain'. Since both use findIndex (first occurrence), this fires when the pair is physically swapped or a stale duplicate END token sits above the real block.","triggerScenarios":"Hand-editing that moves the END comment above BEGIN; copy-pasting the block and leaving an old END token earlier in the file while the true BEGIN/END pair is later (the first END wins); duplicated sections after a bad merge.","commonSituations":"Restructuring the doc and reassembling sections out of order; leaving residue from a previous generated block elsewhere in the file.","solutions":["Order the pair correctly: BEGIN comment above the table, END comment below it","Search the whole file for every occurrence of both tokens and delete stray/duplicate marker lines, keeping exactly one pair","Re-run `pnpm docs:generate` and eyeball the diff — only content between the markers should change"],"exampleFix":"<!-- before -->\n<!-- END GENERATED: provider-chain -->\n| # | Component | Role |\n<!-- BEGIN GENERATED: provider-chain -->\n\n<!-- after -->\n<!-- BEGIN GENERATED: provider-chain -->\n| # | Component | Role |\n<!-- END GENERATED: provider-chain -->","handlingStrategy":"validation","validationCode":"const lines = doc.split('\\n');\nconst b = lines.findIndex(l => l.includes('BEGIN GENERATED: provider-chain'));\nconst e = lines.findIndex(l => l.includes('END GENERATED: provider-chain'));\nif (b === -1 || e === -1 || e <= b) {\n  console.error(`Marker order invalid: BEGIN at ${b}, END at ${e} — exactly one pair, BEGIN above END`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep exactly one BEGIN/END marker pair per generated block; search the file for duplicates after doc restructuring","After reordering doc sections, run `pnpm docs:generate` — a clean splice diff confirms marker order"],"tags":["docs","codegen","markdown","validation"],"backgroundTag":null,"analyzedSha":"a221052e0df5b1f7598fceba7329fd1af95d6699","analyzedAt":"2026-08-16T12:47:06.542Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}