karatelabs/karate · error · RuntimeException

valuesOf() needs one argument

Error message

valuesOf() needs one argument

What it means

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.

Solutions

  1. Pass the map or list: karate.valuesOf(myMap).
  2. Verify the source variable is defined before the call.
  3. If you need keys instead, use the corresponding keysOf helper with the same argument.

Example fix

// before
var vals = karate.valuesOf()
// after
var vals = karate.valuesOf(config)
Defensive patterns

Strategy: type-guard

Validate before calling

if (src == null) { throw new Error('valuesOf() requires a map or list') }

Type guard

function isMapOrList(v) { return v != null && (Array.isArray(v) || typeof v === 'object') }

Try / catch

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 }

Prevention

When it happens

Trigger: 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.

Common situations: Transforming JSON objects into arrays for iteration in tests; refactoring scenario JS where the map variable was renamed; building dynamic assertions over map values.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java:692

                return "";
            }
            return URLDecoder.decode(args[0].toString(), StandardCharsets.UTF_8);
        };
    }

    /**
     * Generate a random UUID string.
     * Usage: karate.uuid() => "550e8400-e29b-41d4-a716-446655440000"
     */
    static JavaInvokable uuid() {
        return args -> UUID.randomUUID().toString();
    }

    @SuppressWarnings("unchecked")
    static JavaInvokable valuesOf() {
        return args -> {
            if (args.length == 0) {
                throw new RuntimeException("valuesOf() needs one argument");
            }
            Object obj = args[0];
            if (obj instanceof Map) {
                return new ArrayList<>(((Map<String, Object>) obj).values());
            } else if (obj instanceof List) {
                return new ArrayList<>((List<?>) obj);
            }
            return new ArrayList<>();
        };
    }

    // ========== OS Utilities ==========

    /**
     * Returns OS information for karate.os.
     * Uses OsUtils for platform detection.
     */
    static Map<String, Object> getOsInfo() {

View on GitHub (pinned to a22eb90246)