{"record":{"id":"de5575b2875dec66","repo":"mozilla/pdf.js","slug":"extractpages-nothing-to-extract","errorCode":null,"errorMessage":"extractPages: nothing to extract.","messagePattern":"extractPages: nothing to extract\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/editor/pdf_editor.js","lineNumber":1096,"sourceCode":"              newPageIndex = 0;\n              this.oldPages[newPageIndex] !== undefined;\n              newPageIndex++\n            ) {\n              /* empty */\n            }\n          }\n        }\n        reservePageSlot(newPageIndex);\n        promises.push(\n          document.getPage(i).then(page => {\n            this.oldPages[newPageIndex] = new PageData(page, documentData);\n          })\n        );\n      }\n    }\n    await Promise.all(promises);\n    if (this.oldPages.length === 0) {\n      throw new Error(\"extractPages: nothing to extract.\");\n    }\n    const copyCounts = new Map();\n    const documents = new Set();\n    for (let i = 0, ii = this.oldPages.length; i < ii; i++) {\n      const pageData = this.oldPages[i];\n      if (pageData === undefined) {\n        throw new Error(\"extractPages: sparse pageIndices.\");\n      }\n      if (pageData) {\n        const { page } = pageData;\n        const copyLevel = copyCounts.get(page) ?? 0;\n        copyCounts.set(page, copyLevel + 1);\n        pageData.copyLevel = copyLevel;\n        documents.add(pageData.documentData.document);\n      }\n    }\n    this.isSingleFile = documents.size === 1;\n    promises.length = 0;","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/editor/pdf_editor.js#L1078-L1114","documentation":"Plain Error thrown after collection completes if this.oldPages is empty (length 0). It means no source page or image actually contributed to the new document, so there is nothing to write out.","triggerScenarios":"Calling extractPages with pageInfos where every entry has no document and no image; all document entries have includePages/excludePages that filter out every page; passing an empty pageInfos array.","commonSituations":"Caller builds pageInfos dynamically and the source list ends up empty; an empty document is passed (numPages=0) and no pages survive filtering.","solutions":["Validate that at least one pageInfo has a document/image and that filtering yields >= 1 page before calling extractPages.","Guard upstream: skip the extractPages call entirely when the result would be empty.","Show a user-facing 'nothing to extract' message rather than crashing."],"exampleFix":"// before\nawait editor.extractPages([], null, primaryDoc, handler, task);\n\n// after\nconst hasContent = pageInfos.some(p => p.document || p.image);\nif (!hasContent) throw new Error('No pages or images selected.');\nawait editor.extractPages(pageInfos, null, primaryDoc, handler, task);","handlingStrategy":"validation","validationCode":"const hasContent = pageInfos.some(p => p.document || p.image);\nif (!hasContent) throw new Error('Nothing to extract: no document or image provided.');","typeGuard":null,"tryCatchPattern":"try {\n  await editor.extractPages(pageInfos, ...);\n} catch (e) {\n  if (e.message === 'extractPages: nothing to extract.') {\n    notifyUser('Select at least one page or image to extract.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Short-circuit upstream when no pageInfo has document/image.","Disable the extract button until the selection is non-empty.","Validate filtered page count >= 1 for each document pageInfo."],"tags":["editor","extract-pages","validation","empty-input"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}