karatelabs/karate · error · Error

Invalid ignore

Error message

Invalid ignore: ${ignore}

What it means

resemble.compare() accepts an options.ignore string that selects which color channel comparison ignores. Only undefined, 'none', 'red', 'green', 'blue', 'alpha' are accepted; anything else hits the default branch and throws. It is a strict enum validation on the caller-supplied options object.

Solutions

  1. Use one of the exact values: undefined/'none', 'red', 'green', 'blue', 'alpha'
  2. Lowercase/trim the option value before passing it
  3. Validate options against the allowed set in your wrapper before calling compare

Example fix

// before
resemble.compare(a, b, { ignore: 'Alpha' }, cb);
// after
resemble.compare(a, b, { ignore: 'alpha' }, cb);
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = [undefined, 'none', 'red', 'green', 'blue', 'alpha'];
if (!ALLOWED.includes(options && options.ignore)) throw new Error('ignore must be one of ' + ALLOWED.join(', '));

Type guard

function isValidIgnore(v) { return v === undefined || ['none','red','green','blue','alpha'].includes(v); }

Try / catch

try { resemble.compare(a, b, opts, cb); } catch (e) { if (String(e.message).startsWith('Invalid ignore:')) { opts.ignore = 'none'; resemble.compare(a, b, opts, cb); } else { throw e; } }

Prevention

When it happens

Trigger: Calling resemble.compare(img1, img2, {ignore: 'transparency'}) or any misspelled channel name such as 'Alpha', 'redes', or 'colour' instead of the exact supported strings.

Common situations: Typos in ignore options, casing mistakes, or copying option values from a different diff library with richer enums.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/18c99613559fd461. Report an issue: GitHub.

Appendix: source

Thrown at karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js:1022

    function applyIgnore(api, ignore, customTolerance) {
        switch (ignore) {
            case "nothing":
                api.ignoreNothing();
                break;
            case "less":
                api.ignoreLess();
                break;
            case "antialiasing":
                api.ignoreAntialiasing();
                break;
            case "colors":
                api.ignoreColors();
                break;
            case "alpha":
                api.ignoreAlpha();
                break;
            default:
                throw new Error("Invalid ignore: " + ignore);
        }

        api.setupCustomTolerance(customTolerance);
    }

    resemble.compare = function (image1, image2, options, cb) {
        var callback;
        var opt;

        if (typeof options === "function") {
            callback = options;
            opt = {};
        } else {
            callback = cb;
            opt = options || {};
        }

        var res = resemble(image1);

View on GitHub (pinned to a22eb90246)