{"record":{"id":"44d053a833f22902","repo":"parallax/jsPDF","slug":"an-unknown-error-occurred-whilst-processing-the-im-44d053","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":1000,"sourceCode":"    format = getImageFileTypeByImageData(imageData);\n    if (!isImageTypeSupported(format)) {\n      throw new Error(\n        \"addImage does not support files of type '\" +\n          format +\n          \"', please ensure that a plugin for '\" +\n          format +\n          \"' support is added.\"\n      );\n    }\n\n    if (!(imageData instanceof Uint8Array)) {\n      imageData = binaryStringToUint8Array(imageData);\n    }\n\n    image = this[\"process\" + format.toUpperCase()](imageData);\n\n    if (!image) {\n      throw new Error(\"An unknown error occurred whilst processing the image\");\n    }\n\n    image.fileType = format;\n\n    return image;\n  };\n})(jsPDF.API);\n","sourceCodeStart":982,"sourceCodeEnd":1008,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/addimage.js#L982-L1008","documentation":"getImageProperties() calls the format-specific processor (processPNG, processJPEG, etc.) and checks that the result is truthy. A falsy return means the processor ran but failed to produce a valid image object — typically due to corrupt or incomplete image data that passed format detection. This mirrors the same catch-all guard in processImageData (error [86]) but applies to the getImageProperties path.","triggerScenarios":"Passing image data with valid magic bytes but a corrupt or truncated body. Passing data where the internal structure (IHDR, SOS markers, etc.) is malformed. Memory or processing errors in the image decoder that return without throwing. A format processor bug that returns null on certain valid inputs.","commonSituations":"Inspecting properties of user-uploaded images that are partially written. Processing images fetched over unreliable connections. Working with images produced by non-standard encoders. Using getImageProperties as a pre-flight check before addImage on untrusted data.","solutions":["Validate the image data integrity before calling getImageProperties","Try-catch around getImageProperties and fall back to default dimensions if it fails","Re-fetch or re-encode the image from the original source","Use a dedicated image validation library to verify the data structure before passing to jsPDF"],"exampleFix":"// before\nvar props = doc.getImageProperties(possiblyCorruptData); // throws\n\n// after - guard with try-catch and defaults\nvar props;\ntry {\n  props = doc.getImageProperties(data);\n} catch (e) {\n  props = { width: 100, height: 100 }; // sensible defaults\n}\ndoc.addImage(data, 'PNG', 10, 10, props.width, props.height);","handlingStrategy":"try-catch","validationCode":"// Pre-validate image data before calling getImageProperties\nfunction tryGetImageProperties(doc, data, fallback) {\n  try {\n    return doc.getImageProperties(data);\n  } catch (e) {\n    console.warn('getImageProperties failed, using fallback:', e.message);\n    return fallback || { width: 100, height: 100 };\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  var props = doc.getImageProperties(imageData);\n} catch (e) {\n  if (e.message.includes('unknown error occurred whilst processing the image')) {\n    // Data is corrupt - use fallback dimensions\n    var props = { width: 200, height: 150 };\n  } else throw e;\n}","preventionTips":["Validate image data in a dedicated image library before passing to jsPDF","Wrap getImageProperties in try-catch with sensible dimension fallbacks","Re-fetch or re-encode images that come from unreliable sources"],"tags":["addimage","corrupt-data","image-properties","catch-all"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}