{"record":{"id":"3db6b0e9921a21cf","repo":"karatelabs/karate","slug":"baseline-image-is-not-a-valid-image","errorCode":null,"errorMessage":"baseline image is not a valid image","messagePattern":"baseline image is not a valid image","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-image/src/main/java/io/karatelabs/ext/image/ImageComparison.java","lineNumber":116,"sourceCode":"\n        this.options = options;\n        this.result = new HashMap<>();\n        this.configure(defaultOptions);\n\n        this.baselineMissing = baselineImg == null || baselineImg.length == 0;\n\n        BufferedImage baselineImage;\n        BufferedImage latestImage;\n\n        try {\n            latestImage = ImageIO.read(new ByteArrayInputStream(latestImg));\n            if (latestImage == null) {\n                throw new RuntimeException(\"latest image is not a valid image\");\n            }\n\n            baselineImage = baselineMissing ? latestImage : ImageIO.read(new ByteArrayInputStream(baselineImg));\n            if (baselineImage == null) {\n                throw new RuntimeException(\"baseline image is not a valid image\");\n            }\n        } catch (IOException e) {\n            logger.error(\"image comparison failed while reading images: {}\", e.getMessage());\n            throw new RuntimeException(e);\n        }\n\n        this.height = baselineImage.getHeight();\n        this.width = baselineImage.getWidth();\n\n        int latestHeight = latestImage.getHeight();\n        int latestWidth = latestImage.getWidth();\n\n        if (width != latestWidth || height != latestHeight) {\n            if (toBool(defaultOptions.get(\"allowScaling\"))) {\n                Image scaledImage = latestImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);\n                latestImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);\n                latestImage.getGraphics().drawImage(scaledImage, 0, 0, null);\n                latestHeight = height;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-image/src/main/java/io/karatelabs/ext/image/ImageComparison.java#L98-L134","documentation":"Same decode check as the latest image but applied to the baseline: ImageIO.read() returned null for the baseline bytes, meaning the baseline exists but is not a decodable image. Note: when the baseline is missing entirely the code reuses the latest image instead, so this error only fires when a baseline was provided yet is unreadable as an image.","triggerScenarios":"Providing a baseline whose bytes are corrupt, empty, an HTML error page, SVG, WebP, or otherwise not decodable by ImageIO; a checked-in baseline that was overwritten or truncated; git-lfs not materializing the file so the pointer text is read.","commonSituations":"Team checked in a corrupted baseline or a placeholder; CI checkout skipped LFS smudge; someone committed a screenshot with a wrong extension; baseline regenerated by a failed tooling run.","solutions":["Open the baseline file locally to confirm it renders; replace it if corrupt","Re-capture the baseline in a controlled environment and commit the valid PNG","Verify git-lfs files materialized (git lfs pull) rather than pointer text","Convert the baseline to a JDK-supported format (PNG/JPEG/BMP/GIF)"],"exampleFix":"// before\nimage.diff({ baseline: 'base.svg', latest: 'shot.png' }) // SVG not decodable\n// after\nimage.diff({ baseline: 'base.png', latest: 'shot.png' })","handlingStrategy":"validation","validationCode":"// Pre-check baseline decodability before diffing\nbyte[] b = karate.readBytes('base.png');\nboolean png = b.length > 8 && (b[0]&0xFF)==0x89 && b[1]=='P';\nif (!png) throw new RuntimeException(\"baseline base.png is not a valid PNG\");","typeGuard":null,"tryCatchPattern":"try {\n    image.diff({ baseline: 'base.png', latest: 'latest.png' });\n} catch (Exception e) {\n    if (String.valueOf(e).contains(\"baseline image is not a valid image\")) {\n        // regenerate the baseline in a controlled environment\n    }\n}","preventionTips":["Regenerate baselines with tooling that validates output, and open them once before committing","Ensure git-lfs smudge runs in CI (git lfs install && git lfs pull)","Keep baselines in JDK-supported formats (PNG/JPEG/BMP/GIF)","Store baselines with checksums to detect corruption early"],"tags":["image","invalid-image","baseline"],"backgroundTag":"invalid-image-content","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}