{"record":{"id":"21483eb183805729","repo":"mozilla/pdf.js","slug":"errormessages","errorCode":null,"errorMessage":"${errorMessages}","messagePattern":"\\$\\{errorMessages\\}","errorType":"exception","errorClass":"JpxError","httpStatus":null,"severity":"error","filePath":"src/core/jpx.js","lineNumber":68,"sourceCode":"    let ptr;\n\n    try {\n      const size = bytes.length;\n      ptr = module._malloc(size);\n      module.writeArrayToMemory(bytes, ptr);\n      const ret = module._jp2_decode(\n        ptr,\n        size,\n        numComponents > 0 ? numComponents : 0,\n        !!isIndexedColormap,\n        !!smaskInData,\n        reducePower\n      );\n      if (ret) {\n        const { errorMessages } = module;\n        if (errorMessages) {\n          delete module.errorMessages;\n          throw new JpxError(errorMessages);\n        }\n        throw new JpxError(\"Unknown error\");\n      }\n      const { imageData } = module;\n      module.imageData = null;\n\n      return imageData;\n    } finally {\n      if (ptr) {\n        module._free(ptr);\n      }\n    }\n  }\n\n  static parseImageProperties(stream) {\n    if (typeof PDFJSDev !== \"undefined\" && PDFJSDev.test(\"IMAGE_DECODERS\")) {\n      if (stream instanceof ArrayBuffer || ArrayBuffer.isView(stream)) {\n        stream = new Stream(stream);","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpx.js#L50-L86","documentation":"Thrown by JpxImage.decode() when the OpenJPEG WASM _jp2_decode returns nonzero (decode failure) and the module surfaced a non-empty errorMessages string. The WASM-side error text is wrapped in a JpxError. This is the structured-failure path: OpenJPEG parsed enough to emit a diagnostic.","triggerScenarios":"Calling jpxImage.decode(bytes, opts) where bytes is a malformed/unusual JPEG2000 codestream or JP2 container that OpenJPEG rejects with an error message (e.g. invalid SIZ, unsupported Part-2 features, truncated codestream).","commonSituations":"A corrupt or partially-downloaded JPX stream in a PDF, a JPEG2000 image using features OpenJPEG doesn't support, or an encrypted stream passed before decryption. The errorMessages field typically contains the opj_xxx C-level reason.","solutions":["Read the wrapped errorMessages text — it usually names the failing marker/component.","Validate the JPEG2000 with a standalone OpenJPEG tool (opj_decompress) to confirm corruption.","Ensure the PDF stream was decrypted and all filters before JPXDecode were applied.","Catch JpxError and fall back to a placeholder image."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { imageData = await JpxImage.instance.decode(bytes); }\ncatch (e) {\n  if (e.name === 'JpxError') { console.warn('JPX decode failed:', e.message); imageData = null; }\n  else throw e;\n}","preventionTips":["Validate JPEG2000 streams with opj_decompress before embedding.","Ensure PDF streams are decrypted and pre-filters applied before JPXDecode.","Catch JpxError and render a placeholder for corrupt JPX images."],"tags":["jpeg2000","image-decoding","wasm","corrupt-data","jpx"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}