santifer/career-ops · error · Error
Could not determine the rendered PDF page count (received ${
Error message
Could not determine the rendered PDF page count (received ${pageCount}). What it means
enforcePageBudget receives pageCount (the number of pages Chromium actually produced) and validates it is a positive integer before comparing against maxPages. This error means pageCount was not a usable integer — null, NaN, 0, undefined, a float, or a negative number. The root cause is upstream: countRenderedPdfPages failed to extract a page count from the PDF buffer, typically because the PDF was empty, corrupt, or unparseable.
Source
Thrown at generate-pdf.mjs:287
throw new Error(message);
}
}
}
/**
* Decide whether a rendered CV fits its configured page budget.
*
* This is deliberately separate from rendering: page count comes from the
* PDF Chromium actually produced, and the renderer never changes layout to
* force content under the limit.
*
* @param {number} pageCount - Actual pages in the rendered PDF.
* @param {{ maxPages?: number, strictPages?: boolean }} [options]
* @returns {void}
*/
export function enforcePageBudget(pageCount, { maxPages = 2, strictPages = false } = {}) {
if (!Number.isInteger(pageCount) || pageCount < 1) {
throw new Error(`Could not determine the rendered PDF page count (received ${pageCount}).`);
}
if (!Number.isInteger(maxPages) || maxPages < 1) {
throw new Error(`Invalid page budget "${maxPages}". Use a positive integer.`);
}
if (pageCount <= maxPages) return;
const actualLabel = 'pages';
const allowedLabel = maxPages === 1 ? 'page' : 'pages';
const message =
`CV is ${pageCount} ${actualLabel}; the allowed maximum is ${maxPages} ${allowedLabel}. ` +
'Trim lower-priority bullets, older roles, secondary projects, or the competencies strip, then regenerate.';
if (strictPages) {
throw new Error(`${message} (--strict-pages requested)`);
}
console.warn(`⚠️ ${message} Continuing because overflow is warning-only by default; use --strict-pages to reject it.`);
}View on GitHub (pinned to 9b17a8ac97)
Solutions
- Verify the Playwright render step succeeded and produced a non-empty PDF buffer.
- Inspect the generated PDF file directly (open it in a viewer or check its size).
- Ensure Chromium is installed and its dependencies are present in the environment (npx playwright install chromium).
- Check that the CV HTML has actual content (not an empty template).
- Debug countRenderedPdfPages by logging the raw PDF buffer and the parsed page count separately.
Defensive patterns
Strategy: validation
Validate before calling
// After rendering, verify the buffer is non-empty before calling enforcePageBudget
if (!pdfBuffer || pdfBuffer.length < 100) {
throw new Error('Playwright returned an empty or near-empty PDF buffer');
}
const pageCount = countRenderedPdfPages(pdfBuffer);
if (!Number.isInteger(pageCount) || pageCount < 1) {
throw new Error(`Page count extraction failed: got ${pageCount} from a ${pdfBuffer.length}-byte buffer`);
}
enforcePageBudget(pageCount, { maxPages }); Type guard
/** @param {unknown} n */
function isPositiveIntegerPageCount(n) {
return typeof n === 'number' && Number.isInteger(n) && n >= 1;
} Try / catch
try {
enforcePageBudget(pageCount, { maxPages: 2 });
} catch (err) {
if (err.message.includes('Could not determine the rendered PDF page count')) {
console.error('PDF page count extraction failed — likely an empty/corrupt PDF. Buffer size:', pdfBuffer.length);
// Investigate: re-render, check Chromium, inspect the HTML
process.exit(1);
}
throw err;
} Prevention
- Verify the Playwright render returned a non-empty buffer before page-count extraction.
- Ensure Chromium is installed (npx playwright install chromium) and its OS deps are present.
- Check that the CV HTML has visible content — an empty or display:none template yields 0 pages.
- Log pdfBuffer.length alongside pageCount to distinguish render failure from parse failure.
When it happens
Trigger: Playwright/Chromium returned an empty or near-empty buffer; the PDF catalog's /Pages dictionary could not be parsed; the render produced 0 pages (blank template, no content); a race condition where the PDF was read before Chromium finished writing.
Common situations: Chromium failed silently (no error thrown but no PDF produced); the CV template rendered no visible content; a headless environment missing Chromium dependencies produced a corrupt PDF; the PDF buffer was truncated.
Related errors
- Could not determine the rendered PDF page count from its pag
- CV section order diverges from cv.md: rendered ${renderedOrd
- Invalid page budget "${maxPages}". Use a positive integer.
- CV is ${pageCount} ${actualLabel}; the allowed maximum is ${
- Unsupported image type: ${extname(inputPath) || '(no extensi
AI-assisted analysis of santifer/career-ops@9b17a8ac97 (2026-08-13).
Data as JSON: /api/errors/7313fd736436ef46.
Report an issue: GitHub.