{"record":{"id":"b6cf5942a70e6f8f","repo":"parallax/jsPDF","slug":"an-unknown-error-occurred-whilst-processing-the-im","errorCode":null,"errorMessage":"An unknown error occurred whilst processing the image.","messagePattern":"An unknown error occurred whilst processing the image\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/addimage.js","lineNumber":914,"sourceCode":"\n    if (!result) {\n      // no need to convert if imageData is already uint8array\n      if (!(imageData instanceof Uint8Array) && format !== \"RGBA\") {\n        dataAsBinaryString = imageData;\n        imageData = binaryStringToUint8Array(imageData);\n      }\n\n      result = this[\"process\" + format.toUpperCase()](\n        imageData,\n        getImageIndex.call(this),\n        alias,\n        checkCompressValue(compression),\n        dataAsBinaryString\n      );\n    }\n\n    if (!result) {\n      throw new Error(\"An unknown error occurred whilst processing the image.\");\n    }\n    return result;\n  };\n\n  /**\n   * @name convertBase64ToBinaryString\n   * @function\n   * @param {string} stringData\n   * @returns {string} binary string\n   */\n  var convertBase64ToBinaryString = (jsPDFAPI.__addimage__.convertBase64ToBinaryString = function(\n    stringData,\n    throwError\n  ) {\n    throwError = typeof throwError === \"boolean\" ? throwError : true;\n    var imageData = \"\";\n    var rawData;\n","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/addimage.js#L896-L932","documentation":"After calling the format-specific processor (e.g., processPNG, processJPEG), processImageData checks that the result is truthy. A falsy return indicates the processor encountered an internal failure but did not throw — typically because the image data was valid enough to pass format detection but corrupt or incomplete at a deeper level. This is a catch-all guard against silently embedding broken image data into the PDF.","triggerScenarios":"Passing truncated or corrupt image data that passes magic-byte detection but fails during decoding. Passing image data with correct headers but invalid body content. Memory issues causing the processor to return without completing. A bug in a custom image processor that returns undefined.","commonSituations":"Fetching images over unreliable networks where the response is truncated. Processing user-uploaded files that are partially written. Base64 strings that were corrupted during transmission. Using a format processor that has a version-specific bug.","solutions":["Validate the image data before passing it to addImage: try opening it in an image viewer or using a validation library","Check that the base64/binary data is complete and not truncated: verify the data length matches expectations","Re-fetch or re-encode the image data from the source","If building a custom processor, ensure it always returns a valid image object or throws a descriptive error"],"exampleFix":"// before - truncated PNG data passes magic bytes but fails processing\ndoc.addImage(truncatedBase64, 'PNG', 10, 10); // throws 'unknown error'\n\n// after - validate completeness first\nvar binary = atob(base64String);\nif (binary.length < MIN_PNG_SIZE) throw new Error('Image data too small');\ndoc.addImage(binary, 'PNG', 10, 10);","handlingStrategy":"try-catch","validationCode":"// Validate image data integrity before processing\nfunction isValidImageData(data, format) {\n  if (!data) return false;\n  if (typeof data === 'string') return data.length > 0;\n  if (data instanceof Uint8Array) return data.length > 100; // minimum header size\n  return true;\n}\n\nif (isValidImageData(imageData, format)) {\n  doc.addImage(imageData, format, 10, 10);\n}","typeGuard":null,"tryCatchPattern":"try {\n  doc.addImage(imageData, format, 10, 10);\n} catch (e) {\n  if (e.message.includes('unknown error occurred whilst processing')) {\n    // Image data is corrupt or incomplete\n    console.error('Image processing failed - data may be corrupt');\n    // Re-fetch or use alternative image source\n  } else throw e;\n}","preventionTips":["Verify image data completeness before passing to addImage","Handle network fetch errors that produce truncated data","Test image data in an image viewer or validator before embedding in PDF"],"tags":["addimage","corrupt-data","image-processing","catch-all"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}