{"record":{"id":"5c6c6e82e121573b","repo":"karatelabs/karate","slug":"failed-to-evaluate","errorCode":null,"errorMessage":"Failed to evaluate {}: {}","messagePattern":"Failed to evaluate (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":503,"sourceCode":"            } 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\";\n            if (name != null) {\n                message = message + \" and name '\" + name + \"'\";\n            }\n            throw new RuntimeException(message);","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L485-L521","documentation":"Evaluating the karate config JavaScript (karate-config.js or a named variant) threw an exception. Karate logs the message and then rethrows a RuntimeException \"Config evaluation failed: <displayName> - <reason>\", aborting scenario startup. This is a hard failure, unlike the non-object return case.","triggerScenarios":"JS syntax error or runtime exception (undefined variable, calling missing function, etc.) inside karate-config.js / evalConfigJs while evalConfig initializes the scenario context.","commonSituations":"karate.env not handled (switch on undefined); typo in karate.* API usage; reading a system property that is null and calling methods on it; broken config after refactor or merge conflict.","solutions":["Read the '{}' detail in the log/exception — the underlying JS error — and fix that line in the config script.","Run the config body in a plain JS engine or node to reproduce and debug the error.","Guard environment-dependent code: `var env = karate.env || 'dev';` and null-check system properties.","Keep a minimal known-good karate-config.js and bisect additions until the failure disappears."],"exampleFix":"// before\nvar key = java.lang.System.getProperty('secret.key').trim();\n// after\nvar key = java.lang.System.getProperty('secret.key');\nif (!key) key = 'default';","handlingStrategy":"try-catch","validationCode":"// smoke-test the config before running suites\nkarate.env = karate.env || 'dev';\nif (!karate.env) throw new Error('karate.env missing');","typeGuard":null,"tryCatchPattern":"try { vars = evalConfigJs(...); } catch (e) { throw new RuntimeException(\"Config evaluation failed: \" + displayName + \" - \" + e.getMessage(), e); }","preventionTips":["Guard against null/undefined karate.env and system properties.","Keep config scripts small; move complex logic into tested JS/Java helpers.","Version-control and review karate-config.js changes like production code."],"tags":["javascript","config","syntax-error"],"backgroundTag":"config-evaluation-failed","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"}