karatelabs/karate · error · RuntimeException

lowerCase() needs one argument

Error message

lowerCase() needs one argument

What it means

lowerCase() is a Karate JS utility that lowercases a String, or (for Maps) converts to JSON, lowercases, and parses back. The library throws this error when it is called with zero arguments, since there is nothing to convert.

Solutions

  1. Pass the value as the first argument: lowerCase(myString) or lowerCase(myMap).
  2. Confirm the variable passed exists and is not undefined due to an earlier failed step.
  3. If the input may be absent, check it before calling lowerCase().

Example fix

// before
def small = lowerCase()
// after
def small = lowerCase(name)
Defensive patterns

Strategy: validation

Validate before calling

def small = text ? lowerCase(text) : ''

Type guard

function safeLowerCase(v) { return v == null ? '' : lowerCase(v) }

Prevention

When it happens

Trigger: Calling karate.lowerCase() with no arguments, e.g. lowerCase() instead of lowerCase(text).

Common situations: Argument dropped during a refactor; calling the function before assigning the source string; copy-paste where the variable name was omitted.

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/995840beb296fc48. Report an issue: GitHub.

Appendix: source

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

            return JsonPath.using(jsonPathConfig).parse(json).read(path);
        };
    }

    @SuppressWarnings("unchecked")
    static JavaInvokable keysOf() {
        return args -> {
            if (args.length == 0) {
                throw new RuntimeException("keysOf() needs one argument");
            }
            Map<String, Object> map = (Map<String, Object>) args[0];
            return new ArrayList<>(map.keySet());
        };
    }

    static JavaInvokable lowerCase() {
        return args -> {
            if (args.length == 0) {
                throw new RuntimeException("lowerCase() needs one argument");
            }
            Object obj = args[0];
            if (obj instanceof String) {
                return ((String) obj).toLowerCase();
            } else if (obj instanceof Map) {
                // Convert to JSON string, lowercase, parse back
                String json = Json.stringifyStrict(obj).toLowerCase();
                return Json.of(json).value();
            } else if (obj instanceof List) {
                String json = Json.stringifyStrict(obj).toLowerCase();
                return Json.of(json).value();
            } else if (obj instanceof Node) {
                String xml = Xml.toString((Node) obj, false).toLowerCase();
                return Xml.toXmlDoc(xml);
            }
            return obj;
        };
    }

View on GitHub (pinned to a22eb90246)