tinyhumansai/openhuman · error · Error

generated-block END marker must come after the BEGIN marker

Error message

generated-block END marker must come after the BEGIN marker

What it means

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.

Source

Thrown at scripts/generate-architecture-docs.mjs:126

 * marker lines (markers preserved). Returns the updated document text.
 *
 * @param {string} docSource
 * @param {string[]} bodyLines
 * @returns {string}
 * @throws if the markers are missing or out of order
 */
export function spliceGeneratedBlock(docSource, bodyLines) {
  const lines = docSource.split('\n');
  const beginIdx = lines.findIndex(l => l.includes(BLOCK_BEGIN_TOKEN));
  const endIdx = lines.findIndex(l => l.includes(BLOCK_END_TOKEN));
  if (beginIdx === -1 || endIdx === -1) {
    throw new Error(
      `generated-block markers not found in ${FRONTEND_DOC}; expected HTML comments ` +
        `containing "${BLOCK_BEGIN_TOKEN}" and "${BLOCK_END_TOKEN}"`
    );
  }
  if (endIdx <= beginIdx) {
    throw new Error('generated-block END marker must come after the BEGIN marker');
  }
  const next = [...lines.slice(0, beginIdx + 1), ...bodyLines, ...lines.slice(endIdx)];
  return next.join('\n');
}

/**
 * Compute the desired doc content from the current sources.
 * @returns {{ updated: string, current: string }}
 */
export function computeFrontendDoc() {
  const providers = parseProviderChain(readFileSync(APP_TSX, 'utf8'));
  const current = readFileSync(FRONTEND_DOC, 'utf8');
  const updated = spliceGeneratedBlock(current, renderProviderChainBody(providers));
  return { updated, current };
}

function main() {
  const check = process.argv.includes('--check');

View on GitHub (pinned to a221052e0d)

Solutions

  1. Order the pair correctly: BEGIN comment above the table, END comment below it
  2. Search the whole file for every occurrence of both tokens and delete stray/duplicate marker lines, keeping exactly one pair
  3. Re-run `pnpm docs:generate` and eyeball the diff — only content between the markers should change

Example fix

<!-- before -->
<!-- END GENERATED: provider-chain -->
| # | Component | Role |
<!-- BEGIN GENERATED: provider-chain -->

<!-- after -->
<!-- BEGIN GENERATED: provider-chain -->
| # | Component | Role |
<!-- END GENERATED: provider-chain -->
Defensive patterns

Strategy: validation

Validate before calling

const lines = doc.split('\n');
const b = lines.findIndex(l => l.includes('BEGIN GENERATED: provider-chain'));
const e = lines.findIndex(l => l.includes('END GENERATED: provider-chain'));
if (b === -1 || e === -1 || e <= b) {
  console.error(`Marker order invalid: BEGIN at ${b}, END at ${e} — exactly one pair, BEGIN above END`);
  process.exit(1);
}

Prevention

When it happens

Trigger: 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.

Common situations: Restructuring the doc and reassembling sections out of order; leaving residue from a previous generated block elsewhere in the file.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@a221052e0d (2026-08-16). Data as JSON: /api/errors/4ac89f0afee1c59e. Report an issue: GitHub.