{"record":{"id":"e13c678cc54261be","repo":"karatelabs/karate","slug":"warn-failed-to-evaluate-scenario-name","errorCode":null,"errorMessage":"[WARN] Failed to evaluate scenario name '{}': {}","messagePattern":"\\[WARN\\] Failed to evaluate scenario name '(.+?)': (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":1450,"sourceCode":"            return;\n        }\n        String trimmed = name.trim();\n        boolean wrappedByBackTick = trimmed.length() > 1\n                && trimmed.charAt(0) == '`'\n                && trimmed.charAt(trimmed.length() - 1) == '`';\n        boolean hasPlaceholder = JS_NAME_PLACEHOLDER.matcher(trimmed).find();\n        if (!wrappedByBackTick && !hasPlaceholder) {\n            return;\n        }\n        String eval = wrappedByBackTick ? trimmed : \"`\" + trimmed + \"`\";\n        try {\n            Object evaluated = karate.engine.eval(eval);\n            if (evaluated != null) {\n                scenario.setName(evaluated.toString());\n            }\n        } catch (Exception e) {\n            String warning = \"[WARN] Failed to evaluate scenario name '\" + trimmed + \"': \" + e.getMessage();\n            logger.warn(warning);\n            // Append to last step's log for report visibility\n            List<StepResult> steps = result.getStepResults();\n            if (!steps.isEmpty()) {\n                StepResult lastStep = steps.get(steps.size() - 1);\n                lastStep.appendLog(warning);\n            }\n        }\n    }\n\n    private static final java.util.regex.Pattern JS_NAME_PLACEHOLDER =\n            java.util.regex.Pattern.compile(\"\\\\$\\\\{.*?}\");\n\n    // ========== Execution Context ==========\n\n    public Object eval(String expression) {\n        return karate.engine.eval(expression);\n    }\n","sourceCodeStart":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L1432-L1468","documentation":"Karate logs this warning when a dynamic scenario name expression (from `Scenario:` or a `name` config) fails to evaluate via the Karate engine. The scenario keeps its original (unevaluated) name and execution continues; the warning is also appended to the last step's log for report visibility. It is non-fatal by design.","triggerScenarios":"A scenario name contains an embedded expression (e.g. `<name>` placeholder interpolation or JS evaluation) that references an undefined variable, throws inside the expression, or is syntactically invalid JS.","commonSituations":"Referencing a variable not yet initialized at scenario-name evaluation time; typos in variable names inside the scenario title; JSON-path expressions over data that is null in the target environment.","solutions":["Check the exception message after the colon to see which variable/expression failed","Ensure all variables referenced in the scenario name are defined before name evaluation (e.g. via Background or bootstrap fixtures)","Simplify the name expression to plain text plus safe concatenation","Wrap risky lookups with a default, e.g. ` #(myVar || 'unknown') ` pattern"],"exampleFix":"// before\nScenario: Test user #(user.name.first)\n// after\nScenario: Test user #(user && user.name && user.name.first || 'unknown')","handlingStrategy":"validation","validationCode":"// Before the scenario runs, ensure name-expression variables exist:\n// in Background or karate-config.js\nif (!karate.get('user')) { karate.set('user', { name: { first: 'unknown' } }); }","typeGuard":"function safeStr(v) { return (v === null || v === undefined) ? 'unknown' : String(v); }","tryCatchPattern":null,"preventionTips":["Keep scenario name expressions trivial (plain text or one safe variable)","Provide defaults for variables used in names via karate-config bootstrap","Treat this warning as informational; verify the displayed name in the report"],"tags":["karate","scenario-name","js-evaluation"],"backgroundTag":"invalid-argument-format","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"}