{"record":{"id":"8e7d9fbae30629f8","repo":"santifer/career-ops","slug":"message-strict-pages-requested","errorCode":null,"errorMessage":"${message} (--strict-pages requested)","messagePattern":"(.+?) \\(--strict-pages requested\\)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"generate-pdf.mjs","lineNumber":1035,"sourceCode":" * @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}\n\n/**\n * Read the page count from the PDF catalog's root /Pages dictionary.\n *\n * Following the catalog reference keeps page-like text in content streams or\n * metadata from being mistaken for an actual page object.\n *\n * @param {Buffer} pdfBuffer - PDF bytes returned by Chromium.\n * @returns {number}\n */\nfunction countRenderedPdfPages(pdfBuffer) {\n  const pdf = pdfBuffer.toString('latin1');\n  const objects = new Map();\n  const objectPattern = /(?:^|[\\r\\n])(\\d+)\\s+(\\d+)\\s+obj\\b([\\s\\S]*?)\\bendobj\\b/g;","sourceCodeStart":1017,"sourceCodeEnd":1053,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/generate-pdf.mjs#L1017-L1053","documentation":"When the rendered CV exceeds the page budget and the strictPages option is set, enforcePageBudget throws this error (the budget message plus a '(--strict-pages requested)' suffix). By default overflow is only a console warning; --strict-pages turns it into a hard failure, e.g. for CI gates that must reject an over-long CV.","triggerScenarios":"Running the PDF generation with --strict-pages (or calling enforcePageBudget with strictPages: true) on a CV whose actual rendered page count exceeds maxPages — e.g. a 3-page CV with the default 2-page budget.","commonSituations":"CI pipelines enforcing a 2-page CV limit fail after a candidate adds roles/bullets; batch renders where one tailored variant overflows; users surprised that plain runs only warn but their scripted --strict-pages run fails.","solutions":["Trim the CV content as the message suggests: cut lower-priority bullets, older roles, secondary projects, or the competencies strip, then regenerate","Raise the budget with a larger --max-pages value if 2 pages is not actually a requirement","Remove --strict-pages if overflow should only warn (default behavior)","Check the rendered output for accidental layout bloat (huge images/margins) inflating the page count"],"exampleFix":"# before (fails)\n$ node generate-pdf.mjs --in cv.html --out cv.pdf --strict-pages\nError: CV is 3 pages; the allowed maximum is 2 pages. ... (--strict-pages requested)\n\n# after: trim content, or relax the gate\n$ node generate-pdf.mjs --in cv.html --out cv.pdf --max-pages=3 --strict-pages","handlingStrategy":"validation","validationCode":"// Pre-flight: render once, count pages, decide before enforcing strictly\nconst pageCount = countRenderedPdfPages(pdfBuffer);\nif (pageCount > maxPages && strictPages) {\n  console.warn(`CV will fail --strict-pages: ${pageCount} pages > ${maxPages}`);\n}","typeGuard":"const fitsBudget = (pageCount, maxPages) => Number.isInteger(pageCount) && pageCount >= 1 && pageCount <= maxPages;","tryCatchPattern":"try {\n  enforcePageBudget(pageCount, { maxPages, strictPages: true });\n} catch (err) {\n  if (err.message.includes('--strict-pages requested')) {\n    console.error('CV exceeds page budget:', err.message);\n    process.exit(1); // CI gate: fail the build with the actionable message\n  }\n  throw err;\n}","preventionTips":["Run --strict-pages in CI to catch CV overflow before sending it out","Trim older roles/bullets whenever the warning (non-strict run) appears","Set an explicit --max-pages matching your real requirement instead of relying on the default of 2","Re-check the page count after every CV content edit"],"tags":["validation","pdf","page-budget","cli"],"backgroundTag":"value-out-of-range","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"}