karatelabs/karate · error · ParserException

' ' is not a valid binding name in strict mode

Error message

'${name}' is not a valid binding name in strict mode

What it means

In strict mode, `eval` and `arguments` may not be used as catch-parameter binding names. Karate validates every name bound by the catch parameter (including destructured bindings) and throws when the script is strict.

Solutions

  1. Rename the catch parameter (e.g. `err`, `ex`).
  2. Update references to the parameter inside the catch block.
  3. If destructuring, keep the property name but change the binding: `catch ({eval: evalValue})` — the property key `eval` is fine, the binding name is not.

Example fix

// before
try { run(); } catch (eval) { log(eval.message); }
// after
try { run(); } catch (err) { log(err.message); }
Defensive patterns

Strategy: validation

Validate before calling

function assertValidCatchBinding(catchSrc) {
  const m = catchSrc.match(/catch\s*\(\s*([\w$]+)/);
  if (m && /^(eval|arguments)$/.test(m[1])) {
    throw new Error("catch binding '" + m[1] + "' is invalid in strict mode");
  }
}

Try / catch

try {
  karate.eval(script);
} catch (e) {
  if (String(e.message).includes("is not a valid binding name in strict mode")) {
    // rename the catch parameter (e.g. to 'err') and its uses
  } else throw e;
}

Prevention

When it happens

Trigger: Writing `try {} catch (eval) {}`, `catch (arguments) {}`, or destructured forms like `catch ({eval: e}) {}` in strict-mode Karate JS.

Common situations: Naming the caught error `eval` by accident or as shorthand; porting old code where the catch var was called `arguments`; strict contexts (class bodies, modules) activating checks that sloppy mode skipped.

Related errors


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

Appendix: source

Thrown at karate-js/src/main/java/io/karatelabs/parser/JsParser.java:1133

            } else {
                binding = ch; // LIT_ARRAY / LIT_OBJECT pattern
                break;
            }
        }
        if (binding == null) {
            return;
        }
        List<String> names = new ArrayList<>();
        collectBoundNames(binding, names);
        String dup = firstDuplicate(names);
        if (dup != null) {
            throw new ParserException(
                    "duplicate binding name '" + dup + "' is not allowed in a catch parameter");
        }
        if (strict) {
            for (String name : names) {
                if (isEvalOrArguments(name)) {
                    throw new ParserException(
                            "'" + name + "' is not a valid binding name in strict mode");
                }
            }
        }
    }

    /** A strict var/let/const declaration may not bind {@code eval} / {@code arguments}
     *  — including inside a destructuring pattern. (Lexical duplicate-BoundNames for
     *  let/const patterns is a distinct rule, deferred — VAR_DECL doesn't carry the
     *  let-vs-var distinction.) */
    private static void checkVarDeclName(Node varDecl) {
        List<String> names = new ArrayList<>();
        collectBindingBoundNames(varDecl, names);
        for (String name : names) {
            if (isEvalOrArguments(name)) {
                throw new ParserException(
                        "'" + name + "' is not a valid binding name in strict mode");
            }

View on GitHub (pinned to a22eb90246)