karatelabs/karate · warning

did not return an object, got

Error message

{} did not return an object, got: {}

What it means

A karate-config.js (or named config JS) evaluated successfully but did not return an object (Map). Karate expects config scripts to return an object of variables; anything else is ignored with this warning and evalConfig proceeds with no config vars. Typically means the script ends without returning a value or returns a primitive/array.

Solutions

  1. Ensure the script's final expression returns an object, e.g. `return {...}` or an object literal as the last statement.
  2. Check the second '{}' in the log — the class name of what was actually returned — and convert it to an object.
  3. If the config intentionally sets no variables, ignore the warning or return an empty object.
  4. Verify the config function is invoked (function() {...}()) if it's an IIFE-style config.

Example fix

// before (karate-config.js)
var env = karate.env; var port = 8080;
// after
var env = karate.env; var port = 8080;
return { env: env, port: port };
Defensive patterns

Strategy: type-guard

Validate before calling

// in karate-config.js, assert before returning
var cfg = { env: karate.env || 'dev' };
if (typeof cfg !== 'object') throw new Error('config must return an object');

Type guard

function isConfigObject(r) { return r !== null && typeof r === 'object' && !Array.isArray(r); }

Prevention

When it happens

Trigger: karate-config.js (or custom config function via evalConfigJs) whose last expression evaluates to a non-object (string, number, undefined), e.g. using statements without a returned object literal.

Common situations: Config file edited so the return was dropped; using a JS file that only performs side effects; returning JSON.stringify(...)'d string instead of the object; calling a function that returns undefined.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java:499

                }
            } else if (fn instanceof JavaCallable callable) {
                // It's a function definition - invoke it
                result = callable.call(null);
            } else {
                // Already evaluated to a value (e.g., object literal)
                result = fn;
            }

            // Apply config variables to engine
            if (result instanceof Map) {
                Map<String, Object> vars = (Map<String, Object>) result;
                for (var entry : vars.entrySet()) {
                    karate.engine.put(entry.getKey(), entry.getValue());
                }
                logger.debug("Evaluated {}: {} variables", displayName, vars.size());
                return vars;
            } else if (result != null) {
                logger.warn("{} did not return an object, got: {}", displayName, result.getClass().getSimpleName());
            }
            return null;
        } catch (Exception e) {
            logger.warn("Failed to evaluate {}: {}", displayName, e.getMessage());
            throw new RuntimeException("Config evaluation failed: " + displayName + " - " + e.getMessage(), e);
        }
    }

    /**
     * Execute the @setup scenario and return all its variables.
     */
    public Map<String, Object> executeSetup(String name) {
        if (featureRuntime == null) {
            throw new RuntimeException("karate.setup() requires a feature context");
        }
        Scenario setupScenario = scenario.getFeature().getSetup(name);
        if (setupScenario == null) {
            String message = "no scenario found with @setup tag";

View on GitHub (pinned to a22eb90246)