{"record":{"id":"44d7e69f186aad08","repo":"karatelabs/karate","slug":"valuesof-needs-one-argument","errorCode":null,"errorMessage":"valuesOf() needs one argument","messagePattern":"valuesOf\\(\\) needs one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":692,"sourceCode":"                return \"\";\n            }\n            return URLDecoder.decode(args[0].toString(), StandardCharsets.UTF_8);\n        };\n    }\n\n    /**\n     * Generate a random UUID string.\n     * Usage: karate.uuid() => \"550e8400-e29b-41d4-a716-446655440000\"\n     */\n    static JavaInvokable uuid() {\n        return args -> UUID.randomUUID().toString();\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    static JavaInvokable valuesOf() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"valuesOf() needs one argument\");\n            }\n            Object obj = args[0];\n            if (obj instanceof Map) {\n                return new ArrayList<>(((Map<String, Object>) obj).values());\n            } else if (obj instanceof List) {\n                return new ArrayList<>((List<?>) obj);\n            }\n            return new ArrayList<>();\n        };\n    }\n\n    // ========== OS Utilities ==========\n\n    /**\n     * Returns OS information for karate.os.\n     * Uses OsUtils for platform detection.\n     */\n    static Map<String, Object> getOsInfo() {","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L674-L710","documentation":"karate.valuesOf() extracts the values of a Map (as an ArrayList) or, for a List, returns a copy of the list. It throws this error when invoked with zero arguments because the source collection is mandatory. Unlike stricter helpers, any single argument of any type is accepted at this guard — type handling happens afterwards.","triggerScenarios":"karate.valuesOf() with no arguments, e.g. karate.valuesOf() in a JS block after the source variable was removed, or calling the function without its argument.","commonSituations":"Transforming JSON objects into arrays for iteration in tests; refactoring scenario JS where the map variable was renamed; building dynamic assertions over map values.","solutions":["Pass the map or list: karate.valuesOf(myMap).","Verify the source variable is defined before the call.","If you need keys instead, use the corresponding keysOf helper with the same argument."],"exampleFix":"// before\nvar vals = karate.valuesOf()\n// after\nvar vals = karate.valuesOf(config)","handlingStrategy":"type-guard","validationCode":"if (src == null) { throw new Error('valuesOf() requires a map or list') }","typeGuard":"function isMapOrList(v) { return v != null && (Array.isArray(v) || typeof v === 'object') }","tryCatchPattern":"try { var vals = karate.valuesOf(src) } catch (e) { if (('' + e).indexOf('needs one argument') >= 0) { throw new Error('valuesOf(): missing source map/list') } throw e }","preventionTips":["Always pass the map or list explicitly","Confirm the source variable is defined before transformation calls","Keep collection transformations in helpers to centralize arity checks"],"tags":["javascript","argument-validation","collections"],"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"}