{"record":{"id":"111b07aadfdca7eb","repo":"karatelabs/karate","slug":"did-not-return-an-object-got","errorCode":null,"errorMessage":"{} did not return an object, got: {}","messagePattern":"(.+?) did not return an object, got: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":499,"sourceCode":"                }\n            } else if (fn instanceof JavaCallable callable) {\n                // It's a function definition - invoke it\n                result = callable.call(null);\n            } else {\n                // Already evaluated to a value (e.g., object literal)\n                result = fn;\n            }\n\n            // Apply config variables to engine\n            if (result instanceof Map) {\n                Map<String, Object> vars = (Map<String, Object>) result;\n                for (var entry : vars.entrySet()) {\n                    karate.engine.put(entry.getKey(), entry.getValue());\n                }\n                logger.debug(\"Evaluated {}: {} variables\", displayName, vars.size());\n                return vars;\n            } else if (result != null) {\n                logger.warn(\"{} did not return an object, got: {}\", displayName, result.getClass().getSimpleName());\n            }\n            return null;\n        } catch (Exception e) {\n            logger.warn(\"Failed to evaluate {}: {}\", displayName, e.getMessage());\n            throw new RuntimeException(\"Config evaluation failed: \" + displayName + \" - \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * Execute the @setup scenario and return all its variables.\n     */\n    public Map<String, Object> executeSetup(String name) {\n        if (featureRuntime == null) {\n            throw new RuntimeException(\"karate.setup() requires a feature context\");\n        }\n        Scenario setupScenario = scenario.getFeature().getSetup(name);\n        if (setupScenario == null) {\n            String message = \"no scenario found with @setup tag\";","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L481-L517","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the script's final expression returns an object, e.g. `return {...}` or an object literal as the last statement.","Check the second '{}' in the log — the class name of what was actually returned — and convert it to an object.","If the config intentionally sets no variables, ignore the warning or return an empty object.","Verify the config function is invoked (function() {...}()) if it's an IIFE-style config."],"exampleFix":"// before (karate-config.js)\nvar env = karate.env; var port = 8080;\n// after\nvar env = karate.env; var port = 8080;\nreturn { env: env, port: port };","handlingStrategy":"type-guard","validationCode":"// in karate-config.js, assert before returning\nvar cfg = { env: karate.env || 'dev' };\nif (typeof cfg !== 'object') throw new Error('config must return an object');","typeGuard":"function isConfigObject(r) { return r !== null && typeof r === 'object' && !Array.isArray(r); }","tryCatchPattern":null,"preventionTips":["Always end karate-config.js with an explicit `return {...}`.","Never return strings/arrays from config scripts.","Lint or smoke-run the config script in isolation."],"tags":["javascript","config","return-value"],"backgroundTag":"unexpected-response-shape","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"}