{"record":{"id":"d557b7042049a536","repo":"MadsLorentzen/ai-job-search","slug":"pdfinfo-output-did-not-contain-a-page-count","errorCode":null,"errorMessage":"pdfinfo output did not contain a page count","messagePattern":"pdfinfo output did not contain a page count","errorType":"exception","errorClass":"VerificationError","httpStatus":null,"severity":"error","filePath":"tools/verify_pdf.py","lineNumber":46,"sourceCode":"            errors=\"replace\",\n        ).stdout\n    except FileNotFoundError as exc:\n        raise VerificationError(\n            f\"required command '{command[0]}' was not found. \"\n            \"Install pypdf (`pip install pypdf`) or poppler-utils \"\n            \"(macOS: brew install poppler, Debian/Ubuntu: apt install poppler-utils, \"\n            \"Windows: choco install poppler)\"\n        ) from exc\n    except subprocess.CalledProcessError as exc:\n        detail = (exc.stderr or \"\").strip() or (exc.stdout or \"\").strip()\n        detail = detail or \"command failed\"\n        raise VerificationError(f\"{command[0]} could not read the PDF: {detail}\") from exc\n\n\ndef parse_page_count(pdfinfo_output):\n    match = re.search(r\"^Pages:\\s+(\\d+)\\s*$\", pdfinfo_output, re.MULTILINE)\n    if not match:\n        raise VerificationError(\"pdfinfo output did not contain a page count\")\n    return int(match.group(1))\n\n\ndef normalize_text(text):\n    return \" \".join(text.split())\n\n\ndef _extract_pypdf(pdf_path):\n    \"\"\"Return (text, pages) or None if pypdf is unavailable, raises, or yields no text.\"\"\"\n    try:\n        from pypdf import PdfReader\n    except ImportError:\n        return None\n    try:\n        reader = PdfReader(str(pdf_path))\n        pages = len(reader.pages)\n        text = \"\\n\".join((page.extract_text() or \"\") for page in reader.pages)\n    except Exception:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/MadsLorentzen/ai-job-search/blob/79cd383e58f0af7948c7c6462a3a289e9b67421e/tools/verify_pdf.py#L28-L64","documentation":"This error is raised by parse_page_count() when the output captured from the `pdfinfo` utility does not contain a line matching `Pages: <number>`. The library relies on that line to determine the PDF's page count, so if pdfinfo produced no parseable Pages field (or was not actually pdfinfo output), verification cannot continue.","triggerScenarios":"Calling parse_page_count() with a string that lacks a `Pages: N` line: empty output, localized pdfinfo output, an error banner from poppler, or output from a different tool. Indirectly hit via verify_pdf() when the pdfinfo path in extract_text_layer() returns malformed/unexpected stdout or stderr text.","commonSituations":"pdfinfo not installed or old/new poppler versions printing differently; shell wrappers or containers mangling output; passing a corrupted PDF so pdfinfo prints an error instead of metadata; passing pdftotext output instead of pdfinfo output.","solutions":["Check that poppler-utils is installed and `pdfinfo file.pdf` manually prints a `Pages:` line","Ensure the string passed to parse_page_count is the captured stdout of pdfinfo, not stderr or another tool's output","If the PDF is corrupt, regenerate or verify it before calling parse_page_count","Upgrade/downgrade poppler-utils if its output format differs, or loosen the regex to tolerate varying whitespace/case"],"exampleFix":"// before\npages = parse_page_count(subprocess.run([\"pdftotext\", path], capture_output=True).stdout)\n// after\npages = parse_page_count(subprocess.run([\"pdfinfo\", path], capture_output=True, text=True).stdout)","handlingStrategy":"validation","validationCode":"import re\ndef pdfinfo_output_looks_valid(out: str) -> bool:\n    return re.search(r'^Pages:\\s+\\d+\\s*$', out, re.MULTILINE) is not None","typeGuard":null,"tryCatchPattern":"try:\n    pages = parse_page_count(out)\nexcept VerificationError as e:\n    raise RuntimeError(f'pdfinfo unusable, raw output: {out!r}') from e","preventionTips":["Always capture pdfinfo stdout with text=True so you pass a decoded string","Assert poppler-utils is installed before running the pipeline","Log raw pdfinfo output when parsing fails to speed diagnosis"],"tags":["pdf","poppler","pdfinfo","parsing","verification"],"backgroundTag":null,"analyzedSha":"79cd383e58f0af7948c7c6462a3a289e9b67421e","analyzedAt":"2026-08-27T21:51:12.330Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}