{"record":{"id":"773032cff1e3465c","repo":"karatelabs/karate","slug":"karate-match-needs-at-least-one-argument","errorCode":null,"errorMessage":"karate.match() needs at least one argument","messagePattern":"karate\\.match\\(\\) needs at least one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":647,"sourceCode":"                        target = new java.util.LinkedHashMap<>();\n                        engine.put(name, target);\n                    }\n                    Json.of(target).set(path, value);\n                }\n            }\n            return null;\n        };\n    }\n\n    /**\n     * V1-compatible karate.match() function.\n     * Usage: karate.match(actual, expected) or karate.match(\"foo == expected\")\n     * Returns { pass: boolean, message: String|null }\n     */\n    private JavaInvokable karateMatch() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"karate.match() needs at least one argument\");\n            }\n            if (args.length >= 2) {\n                // Two-argument form: karate.match(actual, expected)\n                // Do an equals comparison and return { pass, message }\n                Object actual = args[0];\n                Object expected = args[1];\n                try (Value value = Match.evaluate(actual, null, null)) {\n                    return value._equals(expected).toMap();\n                }\n            } else {\n                // One-argument string form: karate.match(\"foo == expected\").\n                // Delegate to the same evaluator the `match` keyword uses so both operands\n                // get identical handling — JsonPath ($-prefixed, wildcards), JSON literals,\n                // embedded expressions, etc. Reusing StepExecutor.evalMatchString keeps the\n                // JS API and the keyword from drifting (issue #2894).\n                //\n                // The string operands are resolved against the *currently executing*\n                // scenario, not the scenario where this `karate` bridge was defined. A","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L629-L665","documentation":"karate.match() exposed to JS requires at least one argument. With zero arguments there is nothing to match, so the JavaInvokable lambda in KarateJs.karateMatch() throws immediately before any evaluation. Karate supports two forms: karate.match(actual, expected) and the single-string form karate.match(\"foo == expected\"); neither is valid empty.","triggerScenarios":"Calling karate.match() with no arguments from JS — e.g. a typo like karate.match() instead of karate.match(actual, expected), or spreading an empty array: karate.match(...arr) where arr is empty.","commonSituations":"Dynamic argument construction (call sites that build the argument list programmatically and pass an empty list), copy-paste edits that removed the operands, or refactors that renamed variables leaving the call empty.","solutions":["Pass the match expression or both operands: karate.match(actual, expected) or karate.match('foo == expected').","If arguments are built dynamically, guard for an empty list before calling and skip or throw a domain-specific error.","Check the spread source isn't empty: karate.match(...parts) fails when parts = []."],"exampleFix":"// before\nkarate.match();\n// after\nkarate.match(response.status, 200);\n// or single-string form\nkarate.match(\"response == { id: '#number' }\");","handlingStrategy":"validation","validationCode":"if (actual === undefined && expected === undefined) {\n  throw new Error('karate.match needs a match expression or (actual, expected)');\n}\nvar result = karate.match(actual, expected);","typeGuard":"function canMatch(args) { return Array.isArray(args) && args.length >= 1 && args[0] != null; }","tryCatchPattern":"var result;\ntry {\n  result = karate.match(actual, expected);\n} catch (e) {\n  if (String(e.message).includes('needs at least one argument')) {\n    result = { pass: false, message: 'match skipped: no operands provided' };\n  } else { throw e; }\n}","preventionTips":["Always call karate.match with either a single string expression or two operands.","When spreading arrays into karate.match, assert the array is non-empty first.","Prefer the two-argument form (actual, expected) in programmatic code to avoid string assembly bugs."],"tags":["javascript","api-misuse","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}