Skip to content

Official Docs Drift, the Generator Fails Loud

Adityo Guni Waluyo

When a documentation generator ingests reports it does not own, tolerant parsing ships truncated pages. Explicit markers plus a throw keep drift visible.

TL;DR

When a report team's HTML restructure broke the generator's extraction markers, the author chose fail-fast over tolerant parsing, because catching and skipping just turns failure into silence. Now missing markers or media halt the build with clear errors. Official documents also get top sidebar placement, backed by eyetracking data on above-the-fold attention.

The generator finished its run, but the terminal carried a single line: Struktur laporan SOP berubah — marker ekstraksi tidak ketemu. I opened the generated manual anyway and the sidebar's "Dokumen Dinas" section was empty, because the build had died right where the extraction should have happened. The team that owns the official reports had just edited their HTML, and the generator refused to continue on top of a structure it no longer recognized.

I did not know exactly what had changed inside their files. My first instinct was the tolerant route: loosen the selectors, add a fallback regex, wrap the extraction in a try-catch, and let the build continue with whatever still parsed. Broken documents get skipped, the rest still ships, and I would check the gap later.

I have run that playbook before. The generator ran, the manual went out, and the missing section only surfaced when a reviewer opened the print output. By then it was far too late. Tolerant parsing hides damage; catch plus skip turns failure into silence.

Explicit markers instead of a quiet regex

The code in generate_manual.mjs takes the opposite path. The extractDoc() function hunts for explicit structure markers: <h2 class="section"> as the start of content, <table class="pengesahan"> as the end, and the pb-lead plus pb-stage classes for the process document. If any marker is missing, it throws; execution stops, and as with any JavaScript error, without a handler up the stack the run terminates [6]. Every runtime failure becomes an Error object that names what broke [3].

function extractDoc(id, html) {
  const start = html.indexOf('<h2 class="section"');
  const end = html.indexOf('<table class="pengesahan">');
  if (start < 0 || end <= start)
    throw new Error('Struktur laporan berubah — marker tidak ketemu');
  return html.slice(start, end);
}

The contract is deliberately plain: a negative indexOf() or an inverted window means the structure moved, and moved structure is not something to parse on good faith. It parallels String.prototype.match(), which returns null when nothing matches [4] — the failure is a value you must acknowledge, not a comment you hope someone reads.

The same rule covers media. docContent() checks every image referenced by a report with fs.existsSync() (the modern, non-deprecated spelling of the existence check [5]); a missing file throws and stops the build. Found images are copied into assets/report/, then every src is rewritten through replace() with a function replacement, which runs once per match and swaps in the new path from its return value [7].

if (!fs.existsSync(abs))
  throw new Error(`Media laporan hilang: ${srcRel}`);
fs.copyFileSync(abs, path.join(outDir, path.basename(srcRel)));
return `src="../../assets/report/${path.basename(srcRel)}"`;

The cost is explicit: whenever the report team changes their HTML shape, the build fails. That is exactly what I am buying. A build-time failure is cheaper than a truncated document in a reader's hands, and the error message names the missing marker, so nobody guesses which selector lost.

Official documents above the routine groups

Placement follows the same discipline of explicit priority. The "Dokumen Dinas" section sits above the 24 admin guide groups. That is not an aesthetic call; it answers scroll-behavior data.

Nielsen Norman Group's 2018 eyetracking study (over 130,000 fixations on a 1920x1080 screen) found users spend about 57% of page-viewing time above the fold, and about 74% within the first two screenfuls [1]. A companion analysis puts the average difference in how users treat information above versus below the fold at 84% [2]. Hidden content, that research notes, only gets seen when readers judge it worth the effort [2].

Two honest limits apply. The numbers come from consumer-web eyetracking, not admin manuals; they indicate priority direction, not precise predictions for this app. And a sidebar is its own scrolled region while the measurements were taken on full-page scroll; the research does not say whether 57% holds inside a sidebar. For a placement decision, the direction is enough: what users must find goes into the first visible position.

The result: the generator treats official documents as first-class citizens. The single source stays the reports' original HTML; the manual is only a regeneration away. Structure moves, the build fails. Media disappears, the build fails. Nothing is allowed to break in silence.

Sources

  1. Nielsen Norman Group, Scrolling and Attention (2018)
  2. Nielsen Norman Group, The Fold Manifesto
  3. MDN Web Docs, Error
  4. MDN Web Docs, String.prototype.match()
  5. Node.js Docs, fs.existsSync()
  6. MDN Web Docs, throw statement
  7. MDN Web Docs, String.prototype.replace()

Related articles