{"record":{"id":"d965da551d4f815b","repo":"mozilla/pdf.js","slug":"getdocument-expected-either-data-range-or","errorCode":null,"errorMessage":"getDocument - expected either `data`, `range`, or `url` parameter.","messagePattern":"getDocument - expected either `data`, `range`, or `url` parameter\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/api.js","lineNumber":442,"sourceCode":"          disableRange,\n          disableStream,\n        });\n      } else if (url) {\n        if (typeof PDFJSDev !== \"undefined\" && PDFJSDev.test(\"MOZCENTRAL\")) {\n          throw new Error(\"Not implemented: NetworkStream\");\n        }\n        const NetworkStream = getNetworkStream(url);\n\n        networkStream = new NetworkStream({\n          url,\n          httpHeaders,\n          withCredentials,\n          rangeChunkSize,\n          disableRange,\n          disableStream,\n        });\n      } else {\n        throw new Error(\n          \"getDocument - expected either `data`, `range`, or `url` parameter.\"\n        );\n      }\n\n      return workerIdPromise.then(workerId => {\n        if (worker.destroyed) {\n          throw new Error(\"Worker was destroyed\");\n        }\n\n        const messageHandler = new MessageHandler(docId, workerId, worker.port);\n        const transport = new WorkerTransport(\n          messageHandler,\n          task,\n          networkStream,\n          transportParams,\n          transportFactory,\n          pagesMapper\n        );","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/api.js#L424-L460","documentation":"A generic Error from getDocument when none of data, rangeTransport (range), or url was supplied in the source parameters. At least one of these is mandatory; the loader cannot obtain PDF bytes otherwise. The branch is the final else after data/range/url checks.","triggerScenarios":"Calling getDocument({}) or getDocument({ foo: bar }) with no recognized source field; passing a source object whose data/range/url keys are undefined (e.g. typo, destructuring bug, or late-assigned variable).","commonSituations":"Missing input file/URL in a dynamic UI before the user selected one; wrong key name (e.g. byteArray instead of data); Node.js usage forgetting to read the file into a buffer.","solutions":["Provide exactly one of data (Uint8Array/ArrayBuffer), url (string), or range (PDFDataRangeTransport) in the getDocument source.","Guard the call site: only invoke getDocument once the source field is non-empty.","For Node, read the file: const data = new Uint8Array(fs.readFileSync(path))."],"exampleFix":"// before\npdfjsLib.getDocument({}); // throws\npdfjsLib.getDocument({ path }); // typo: 'path' is not recognized\n\n// after\nconst data = new Uint8Array(fs.readFileSync(path));\npdfjsLib.getDocument({ data });","handlingStrategy":"validation","validationCode":"function assertSource(src) {\n  if (!src || (!src.data && !src.url && !src.range)) {\n    throw new Error('getDocument needs one of: data, url, range');\n  }\n}\nassertSource(src);\npdfjsLib.getDocument(src);","typeGuard":"// Type guard narrowing a valid getDocument source.\nfunction isValidPdfSource(src) {\n  return !!src && (\n    src.data instanceof Uint8Array ||\n    typeof src.url === 'string' ||\n    !!src.range\n  );\n}","tryCatchPattern":null,"preventionTips":["Validate the source object has data, url, or range before calling getDocument.","Use TypeScript types from pdfjs-dist to catch missing keys at compile time.","Guard UI so getDocument is only called after the user supplies input."],"tags":["api-usage","configuration","getdocument","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}