{"record":{"id":"8427555196bd29c5","repo":"karatelabs/karate","slug":"keysof-needs-one-argument","errorCode":null,"errorMessage":"keysOf() needs one argument","messagePattern":"keysOf\\(\\) needs one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":295,"sourceCode":"            if (args.length < 2) {\n                throw new RuntimeException(\"jsonPath() needs two arguments: object and path\");\n            }\n            Object json = args[0];\n            if (json instanceof Node node) {\n                // v1 parity: an XML argument is converted to a Map first, otherwise jayway\n                // sees an opaque scalar and no path can match\n                json = Xml.toObject(node);\n            }\n            String path = args[1].toString();\n            return JsonPath.using(jsonPathConfig).parse(json).read(path);\n        };\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    static JavaInvokable keysOf() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"keysOf() needs one argument\");\n            }\n            Map<String, Object> map = (Map<String, Object>) args[0];\n            return new ArrayList<>(map.keySet());\n        };\n    }\n\n    static JavaInvokable lowerCase() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"lowerCase() needs one argument\");\n            }\n            Object obj = args[0];\n            if (obj instanceof String) {\n                return ((String) obj).toLowerCase();\n            } else if (obj instanceof Map) {\n                // Convert to JSON string, lowercase, parse back\n                String json = Json.stringifyStrict(obj).toLowerCase();\n                return Json.of(json).value();","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L277-L313","documentation":"Arity guard in the karate.keysOf() JS utility: it requires one argument, the map/object whose keys should be returned. Fires when keysOf() is called with no argument; pass the object to extract keys from.","triggerScenarios":"Calling karate.keysOf() with no arguments from a Karate script, e.g. keysOf() instead of keysOf(myMap).","commonSituations":"Typo or refactor left the call without its argument; passing a variable that was removed during editing; copying a snippet where the argument was a placeholder.","solutions":["Pass the map as the first argument: keysOf(myMap).","Verify the variable holding the map is defined and in scope before the call.","If the value may be missing, guard the call with an existence check before invoking keysOf()."],"exampleFix":"// before\ndef keys = keysOf()\n// after\ndef keys = keysOf(myMap)","handlingStrategy":"validation","validationCode":"// in Karate JS, before calling\ndef keys = map ? keysOf(map) : []","typeGuard":"function safeKeysOf(v) { return v && typeof v === 'object' && !(v instanceof Array) ? keysOf(v) : [] }","tryCatchPattern":null,"preventionTips":["Count arguments at the call site: keysOf takes exactly one map.","Define the map variable in a prior step before calling keysOf.","Wrap in a helper with a default for missing maps."],"tags":["karate","javascript","argument-count","maps"],"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-19T12:17:13.211Z"}