santifer/career-ops · error · Error
Could not determine the rendered PDF page count
Error message
Could not determine the rendered PDF page count (received ${pageCount}). What it means
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.
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
Example fix
// before
enforcePageBudget(Number(pageCountStr));
// after
const pageCount = Number(pageCountStr);
if (!Number.isInteger(pageCount) || pageCount < 1) throw new Error(`bad page count: ${pageCountStr}`);
enforcePageBudget(pageCount, { maxPages: 2, strictPages: true }); Defensive patterns
Strategy: type-guard
Validate before calling
function safeEnforcePageBudget(pageCount, opts) {
if (!Number.isInteger(pageCount) || pageCount < 1) {
throw new TypeError(`pageCount must be a positive integer, got ${pageCount}`);
}
return enforcePageBudget(pageCount, opts);
} Type guard
const isValidPageCount = (n) => Number.isInteger(n) && n >= 1;
Try / catch
try {
enforcePageBudget(pageCount, { maxPages: 2, strictPages: true });
} catch (err) {
if (err.message.includes('Could not determine the rendered PDF page count')) {
console.error('Page count missing/invalid — check that the PDF rendered and the count was parsed:', err.message);
return null;
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- (--strict-pages requested)
- Unsupported image type
- 4dayweek: invalid URL
- 4dayweek: URL must use HTTPS
- a 40-hex commit --sha is required
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/7313fd736436ef46.
Report an issue: GitHub.
Appendix: source
Thrown at generate-pdf.mjs:1021
const reordered = out + html.slice(cursor);
reportUnresolved();
return reordered;
}
/**
* 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 aac998c7ed)