{"record":{"id":"d1e8a1483b793402","repo":"mozilla/pdf.js","slug":"pagelabel-is-not-a-dictionary","errorCode":null,"errorMessage":"PageLabel is not a dictionary.","messagePattern":"PageLabel is not a dictionary\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/catalog.js","lineNumber":869,"sourceCode":"  #readPageLabels() {\n    const nums = this.rawPageLabels;\n    if (!nums) {\n      return null;\n    }\n\n    const pageLabels = new Array(this.numPages);\n    let style = null,\n      prefix = \"\";\n\n    let currentLabel = \"\",\n      currentIndex = 1;\n\n    for (let i = 0, ii = this.numPages; i < ii; i++) {\n      const labelDict = nums.get(i);\n\n      if (labelDict !== undefined) {\n        if (!(labelDict instanceof Dict)) {\n          throw new FormatError(\"PageLabel is not a dictionary.\");\n        }\n\n        if (\n          labelDict.has(\"Type\") &&\n          !isName(labelDict.get(\"Type\"), \"PageLabel\")\n        ) {\n          throw new FormatError(\"Invalid type in PageLabel dictionary.\");\n        }\n\n        if (labelDict.has(\"S\")) {\n          const s = labelDict.get(\"S\");\n          if (!(s instanceof Name)) {\n            throw new FormatError(\"Invalid style in PageLabel dictionary.\");\n          }\n          style = s.name;\n        } else {\n          style = null;\n        }","sourceCodeStart":851,"sourceCodeEnd":887,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/catalog.js#L851-L887","documentation":"Thrown in Catalog.#readPageLabels() (catalog.js:869) when an entry retrieved from the PageLabels NumberTree (numbered by page index) is not a Dict. Each PageLabel entry should be a dictionary describing the label style/prefix/start for a page range. Note: the pageLabels getter wraps #readPageLabels in try/catch and downgrades this FormatError to a 'Unable to read page labels.' warning, returning null labels — so the user-visible effect is loss of page labels, not a load failure.","triggerScenarios":"nums.get(i) returns a defined value that is not a Dict (e.g., a string, name, or array stored in the PageLabels number tree). Reached when pdfDocument.pageLabels is read or when the viewer requests page labels for the sidebar.","commonSituations":"A PDF producer that wrote a malformed PageLabels tree; a corrupt number-tree leaf; an edited PDF with hand-added bad entries. Low frequency; usually only affects label display.","solutions":["This error is already caught and degraded to a warning by the pageLabels getter — no labels will display, but the document loads. Confirm labels are non-essential for your use case.","Repair the PDF with qpdf/mutool to rebuild a clean PageLabels tree if labels matter.","If generating PDFs, ensure each PageLabels leaf is a proper dictionary with /S, /P, /St keys.","Treat pdfDocument.pageLabels === null as 'labels unavailable' rather than an error in your UI."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Labels are optional metadata; you cannot cheaply pre-validate the number tree.\n// Design UI so null pageLabels is a normal 'no labels' state.","typeGuard":null,"tryCatchPattern":"// PDF.js already catches this in the pageLabels getter and warns.\n// Treat null as 'labels unavailable':\nconst labels = pdf.pageLabels; // may be null after a console warning\nif (!labels) {\n  // fall back to plain 1..numPages numbering\n}","preventionTips":["Treat pdfDocument.pageLabels === null as a valid 'no labels' outcome, not an error.","Repair the PDF (qpdf/mutool) if labels are required.","When producing PDFs, make each PageLabels leaf a proper dictionary.","Do not assume pageLabels is always populated for every document."],"tags":["pdf-structure","catalog","page-labels","corrupt-pdf","number-tree"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}