{"record":{"id":"7313fd736436ef46","repo":"santifer/career-ops","slug":"could-not-determine-the-rendered-pdf-page-count-r","errorCode":null,"errorMessage":"Could not determine the rendered PDF page count (received ${pageCount}).","messagePattern":"Could not determine the rendered PDF page count \\(received (.+?)\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"generate-pdf.mjs","lineNumber":1021,"sourceCode":"  const reordered = out + html.slice(cursor);\n  reportUnresolved();\n  return reordered;\n}\n\n/**\n * Decide whether a rendered CV fits its configured page budget.\n *\n * This is deliberately separate from rendering: page count comes from the\n * PDF Chromium actually produced, and the renderer never changes layout to\n * force content under the limit.\n *\n * @param {number} pageCount - Actual pages in the rendered PDF.\n * @param {{ maxPages?: number, strictPages?: boolean }} [options]\n * @returns {void}\n */\nexport function enforcePageBudget(pageCount, { maxPages = 2, strictPages = false } = {}) {\n  if (!Number.isInteger(pageCount) || pageCount < 1) {\n    throw new Error(`Could not determine the rendered PDF page count (received ${pageCount}).`);\n  }\n  if (!Number.isInteger(maxPages) || maxPages < 1) {\n    throw new Error(`Invalid page budget \"${maxPages}\". Use a positive integer.`);\n  }\n  if (pageCount <= maxPages) return;\n\n  const actualLabel = 'pages';\n  const allowedLabel = maxPages === 1 ? 'page' : 'pages';\n  const message =\n    `CV is ${pageCount} ${actualLabel}; the allowed maximum is ${maxPages} ${allowedLabel}. ` +\n    'Trim lower-priority bullets, older roles, secondary projects, or the competencies strip, then regenerate.';\n\n  if (strictPages) {\n    throw new Error(`${message} (--strict-pages requested)`);\n  }\n\n  console.warn(`⚠️  ${message} Continuing because overflow is warning-only by default; use --strict-pages to reject it.`);\n}","sourceCodeStart":1003,"sourceCodeEnd":1039,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/generate-pdf.mjs#L1003-L1039","documentation":"enforcePageBudget in generate-pdf.mjs validates its pageCount argument before applying the CV page budget. If pageCount is not a positive integer (NaN, undefined, 0, a float), the function cannot know the rendered page count and throws instead of guessing — the budget decision is meaningless without a real count from the rendered PDF.","triggerScenarios":"Calling enforcePageBudget directly (it is exported) with a page count that failed to parse: countRenderedPdfPages returned 0, a caller passed Number(undefined), or a JSON/CLI value like '2' (string) or 2.5 was forwarded instead of an integer.","commonSituations":"Custom scripts importing the exported function and passing an unparsed or failed page count; a broken PDF making the upstream count 0/NaN; refactoring that renamed the page-count variable and passed undefined.","solutions":["Fix the caller to pass a positive integer page count obtained from countRenderedPdfPages on the actual PDF buffer","Check the PDF produced by Chromium is complete and non-empty — a failed render yields no parseable page tree","Coerce and validate before calling: Number.isInteger(n) && n >= 1","Log the intermediate value to see where the count became invalid"],"exampleFix":"// before\nenforcePageBudget(Number(pageCountStr));\n// after\nconst pageCount = Number(pageCountStr);\nif (!Number.isInteger(pageCount) || pageCount < 1) throw new Error(`bad page count: ${pageCountStr}`);\nenforcePageBudget(pageCount, { maxPages: 2, strictPages: true });","handlingStrategy":"type-guard","validationCode":"function safeEnforcePageBudget(pageCount, opts) {\n  if (!Number.isInteger(pageCount) || pageCount < 1) {\n    throw new TypeError(`pageCount must be a positive integer, got ${pageCount}`);\n  }\n  return enforcePageBudget(pageCount, opts);\n}","typeGuard":"const isValidPageCount = (n) => Number.isInteger(n) && n >= 1;","tryCatchPattern":"try {\n  enforcePageBudget(pageCount, { maxPages: 2, strictPages: true });\n} catch (err) {\n  if (err.message.includes('Could not determine the rendered PDF page count')) {\n    console.error('Page count missing/invalid — check that the PDF rendered and the count was parsed:', err.message);\n    return null;\n  }\n  throw err;\n}","preventionTips":["Always obtain pageCount from countRenderedPdfPages on the actual PDF buffer, never from unparsed strings","Check the PDF render succeeded (non-empty buffer starting with %PDF-) before counting","Validate intermediate numeric conversions before passing them on","Log the raw count value when debugging budget failures"],"tags":["validation","pdf","page-count"],"backgroundTag":"invalid-argument-value","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}