Static generation failure handling
What you need to know
Static generation depends on trustworthy build-time inputs. A valid missing record, an unavailable repository and a malformed inventory should not be treated as the same event. A build can fail before deployment; that is often preferable to silently shipping incomplete content.
By the end, you can: design missing-data tests; record build failure and recovery.
Validate a small build inventory (standalone helper)
export function buildParams(rows: unknown): { slug: string }[] { if (!Array.isArray(rows) || rows.length > 100) throw new Error("Invalid article inventory"); const slugs = new Set<string>(); for (const row of rows as unknown[]) { if (!row || typeof row !== "object" || !("slug" in row) || typeof row.slug !== "string" || row.slug.length > 60 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(row.slug)) { throw new Error("Invalid article slug"); } if (slugs.has(row.slug)) throw new Error("Duplicate article slug"); slugs.add(row.slug); } return Array.from(slugs, slug => ({ slug }));}Expected behavior (not framework-tested): Two distinct valid rows yield two parameter objects. This fixture allows lowercase letters and digits separated by single hyphens, at most 60 characters; it rejects leading, trailing or repeated hyphens. This is a local publishing policy, not a universal Next.js URL rule. A duplicate or malformed slug throws before a broken path list is used.
How it works
At build time validate the published inventory separately from page lookup. A known missing public article can display not-found UI; a failed repository read should be surfaced as an operational failure. Build and promote an immutable artifact only after successful checks. If an ISR regeneration fails, consult the selected version’s regeneration behavior and test whether the last good output remains; this differs from an initial build failure. Keep the prior deployment available for rollback. Do not claim a failed build automatically rolls back any hosting platform.
Separate negative build cases (expected plan)
Case A: inventory has moss and fern → build eligible routesCase B: duplicate moss → generator rejects inventoryCase C: published list references deleted book → page missing-data policyCase D: repository unavailable → fail build; do not promote artifactCase E: eligible regeneration fails → inspect last good output and retry behaviorExpected behavior (not framework-tested): Cases A–E require independent setup and observations. Only the standalone inventory validation is covered by local pure tests.
Common mistake
Do not replace a failed inventory call with [] just to obtain a successful build. An empty inventory may be legitimate but must be an explicit successful result. Avoid large unbounded path lists: build time, memory and artifact size are real constraints.
Practice and verification
Prepare an inventory with a duplicate and one invalid slug. Correct both, then simulate an unavailable source. Specify what counts as a successful deployment and which previous artifact should be retained. Use a disposable fixture, not a production CMS.
Scope: App Router, proposed Next.js 16.x, Cache Components disabled for these labs. Snippets assume a reviewed TypeScript app and are static examples; framework behavior has not been executed. Exact supported patch and dependency set must be verified before running.
Further reading: Static Params · Isr · Errors