karatelabs/karate · error · Error
No diff image available - ran in compareOnly mode
Error message
No diff image available - ran in compareOnly mode
What it means
resemble.js's getImageDataUrl() builds a visual diff image, but when the comparison ran in compareOnly mode no diff canvas exists, so calling it throws this JavaScript Error. In Karate image testing this means you requested the diff image output from a comparison that was configured to only compute the mismatch percentage.
Solutions
- Disable compareOnly in the image-comparison configuration so a diff image is generated
- Wrap getImageDataUrl in a check/try so it's only called when compareOnly is false
- If you only need the mismatch percentage, avoid calling getImageDataUrl entirely
Example fix
// before
var diff = result.getImageDataUrl('diff'); // throws in compareOnly
// after
if (!result.compareOnly) { var diff = result.getImageDataUrl('diff'); } else { karate.warn('diff image skipped'); }
// or re-run comparison with compareOnly = false in config Defensive patterns
Strategy: fallback
Validate before calling
// before requesting a diff image
if (config.compareOnly) { karate.warn('compareOnly mode: no diff image'); } else { /* getImageDataUrl safe */ }
Type guard
function hasDiffImage(result) { return !result.compareOnly; }
Try / catch
try { diffUrl = result.getImageDataUrl('diff'); } catch (e) { diffUrl = null; /* compareOnly mode */ }
Prevention
- Enable diff-image mode in config when reports need diffs
- Guard getImageDataUrl calls behind a compareOnly check
- Keep compareOnly only for fast percentage-only checks
When it happens
Trigger: Calling data.getImageDataUrl(text) (or requesting diff-image output from karate's image match config) on a resemblance result produced with compareOnly enabled.
Common situations: karate-config for image matching set to compareOnly to save time/space, then later code (report generation, failure output) tries to render a diff image.
Related errors
- did not return an object, got
- Failed to evaluate
- a class declaration may not be the body of
- a function declaration may not be the body of
- a lexical declaration may not be the body of
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/dade44c7e9576a67.
Report an issue: GitHub.
Appendix: source
Thrown at karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js:673
}
if (compareOnly) {
var currentMisMatchPercent = (mismatchCount / (height * width)) * 100;
if (currentMisMatchPercent > returnEarlyThreshold) {
skipTheRest = true;
}
}
});
data.rawMisMatchPercentage = (mismatchCount / (height * width)) * 100;
data.misMatchPercentage = data.rawMisMatchPercentage.toFixed(2);
data.diffBounds = diffBounds;
data.analysisTime = Date.now() - time;
data.getImageDataUrl = function (text) {
if (compareOnly) {
throw Error("No diff image available - ran in compareOnly mode");
}
var barHeight = 0;
if (text) {
barHeight = addLabel(text, context, hiddenCanvas);
}
context.putImageData(imgd, 0, barHeight);
return hiddenCanvas.toDataURL("image/png");
};
if (!compareOnly && hiddenCanvas.toBuffer) {
data.getBuffer = function (includeOriginal) {
if (includeOriginal) {
var imageWidth = hiddenCanvas.width + 2;
hiddenCanvas.width = imageWidth * 3;View on GitHub (pinned to a22eb90246)