karatelabs/karate · error · JsErrorException (typeError)

cannot get from

Error message

cannot get from: ${node}

What it means

`PropertyAccess.get` switches on the AST node type of the expression being read; node kinds that cannot yield a value (unsupported reference forms) fall into the default branch and throw this TypeError with the offending node in the message. It indicates the expression form is not a readable value in Karate's JS grammar.

Solutions

  1. Rewrite the expression into a supported form (parenthesize the sub-expression or assign it to a variable first).
  2. Check the embedded JS for unsupported syntax and simplify it.
  3. Upgrade karate-js to a version whose get-handler covers the syntax used.

Example fix

// before
var x = obj.a.b; // written as an unsupported bare ref chain node
// after
var x = (obj.a).b; // or: var t = obj.a; var x = t.b;
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-parse and whitelist supported node forms before evaluating
const supported = /^(lit|paren|ref|call)/i;
if (expr && !supported.test(expr.trim())) throw new Error('unsupported get expression: ' + expr);

Type guard

function isReadable(expr) { return typeof expr === 'string' && !/^(new|delete|typeof)\b/.test(expr.trim()); }

Try / catch

try { v = engine.get(path); } catch (e) { if (String(e.message).startsWith('cannot get from:')) { v = fallbackEval(path); } else { throw e; } }

Prevention

When it happens

Trigger: Evaluating a get against a node type not in the handled set (REF_EXPR, REF_DOT_EXPR, REF_BRACKET_EXPR, LIT_EXPR, PAREN_EXPR, FN_CALL_EXPR) — typically a malformed or unsupported expression reaching the property-access layer, e.g. from a dynamically built or mis-parsed expression.

Common situations: Embedded JS expressions in Karate features with syntax the engine partially parses (e.g. `new Foo` without call context, arrow bodies in unusual positions); version mismatches where newer syntax hits an older handler table.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java:236

        setByName(site.target,
                site.isIndex ? Terms.toPropertyKey(site.key) : (String) site.key,
                value, context, trackingNode, site.receiver);
    }

    //=== Simple get/set operations ===

    /**
     * Get a property value from a node expression.
     */
    static Object get(Node node, CoreContext context) {
                return switch (node.type) {
            case REF_EXPR -> getRefExpr(node, context, false);
            case REF_DOT_EXPR -> getRefDotExpr(node, context, false);
            case REF_BRACKET_EXPR -> getRefBracketExpr(node, context, false);
            case LIT_EXPR -> Interpreter.eval(node, context);
            case PAREN_EXPR -> Interpreter.eval(node.get(1), context);
            case FN_CALL_EXPR -> Interpreter.eval(node, context);
            default -> throw JsErrorException.typeError("cannot get from: " + node);
        };
    }

    /**
     * Get a callable for method invocation, publishing its receiver (this
     * object) through {@link CoreContext#callReceiver} — read it immediately
     * after this returns, before any further evaluation (see the field's
     * contract note). For method calls like obj.method(), the receiver is
     * obj; for direct calls like foo(), it is null.
     */
    static Object getCallable(Node node, CoreContext context) {
        return switch (node.type) {
            case REF_EXPR -> {
                Object c = getRefExpr(node, context, true);
                context.callReceiver = null;
                yield c;
            }
            case REF_DOT_EXPR -> getCallableRefDotExpr(node, context);

View on GitHub (pinned to a22eb90246)