{"record":{"id":"de9a2625cc9f1e2b","repo":"karatelabs/karate","slug":"ka-data-requires-format-varname-expression-got-attrvalue","errorCode":null,"errorMessage":"ka:data requires format 'varName:expression', got: ${attrValue}","messagePattern":"ka:data requires format 'varName:expression', got: (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/markup/KaDataProcessor.java","lineNumber":89,"sourceCode":"    protected void doProcess(ITemplateContext ctx, IModel model, IElementModelStructureHandler sh) {\n        if (model.size() == 0) {\n            return;\n        }\n\n        // Get the opening tag\n        IProcessableElementTag openTag = (IProcessableElementTag) model.get(0);\n        String elementName = openTag.getElementCompleteName().toLowerCase();\n\n        // Get attribute value: \"varName:serverExpression\"\n        String attrValue = openTag.getAttributeValue(getDialectPrefix(), DATA);\n        if (attrValue == null || attrValue.isEmpty()) {\n            return;\n        }\n\n        // Parse \"varName:expression\"\n        int colonIndex = attrValue.indexOf(':');\n        if (colonIndex <= 0) {\n            throw new RuntimeException(\"ka:data requires format 'varName:expression', got: \" + attrValue);\n        }\n\n        String varName = attrValue.substring(0, colonIndex).trim();\n        String expression = attrValue.substring(colonIndex + 1).trim();\n\n        // Evaluate the server expression to get initial data\n        MarkupTemplateContext kec = (MarkupTemplateContext) ctx;\n        Object initialData = kec.evalLocal(expression);\n        String jsonData = initialData != null ? Json.stringifyStrict(initialData) : \"{}\";\n\n        IModelFactory modelFactory = ctx.getModelFactory();\n\n        // Build new attributes map (common for all elements)\n        Map<String, String> newAttrs = new HashMap<>();\n        for (var attr : openTag.getAllAttributes()) {\n            String name = attr.getAttributeCompleteName();\n            if (!name.equals(getDialectPrefix() + \":\" + DATA)) {\n                newAttrs.put(name, attr.getValue());","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/markup/KaDataProcessor.java#L71-L107","documentation":"The ka:data processor parses its attribute value as 'varName:expression' (split on the first colon) and throws a plain RuntimeException when there is no colon or the colon is the first character (varName empty). The attribute value must name the client-side variable to populate and a server-side expression providing the initial data.","triggerScenarios":"Writing ka:data=\"something\" without a colon, ka:data=\":expr\" with an empty variable name, or quoting/HTML-escaping that mangles the value so the colon is lost.","commonSituations":"Copy-pasting ka:data examples incompletely; forgetting the expression half when refactoring; HTML entity encoding (&#58;) hiding the colon from the processor; dynamic templates building the attribute value wrongly.","solutions":["Rewrite the attribute as ka:data=\"varName:expression\" with a non-empty variable name before the first colon","Ensure the expression after the colon is a valid server-side expression resolvable in the template context","Avoid HTML-entity-encoding the colon; write it literally","Check rendered/template-manager output to confirm the attribute value reaches the processor intact"],"exampleFix":"<!-- before -->\n<div ka:data=\"userData\"></div>\n<!-- after -->\n<div ka:data=\"userData:session.user\"></div>","handlingStrategy":"validation","validationCode":"if (attrValue == null || attrValue.indexOf(':') <= 0) throw new IllegalArgumentException(\"ka:data needs 'varName:expression', got: \" + attrValue);","typeGuard":"boolean valid = attrValue != null && attrValue.indexOf(':') > 0;","tryCatchPattern":"try { render(template, model); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().startsWith(\"ka:data requires format\")) { log.error(\"bad ka:data attribute: {}\", e.getMessage()); } throw e; }","preventionTips":["Always write ka:data=\"varName:expression\" with a non-empty varName","Write the colon literally — do not HTML-entity-encode it","Template-check ka:data values in CI with a simple regex"],"tags":["markup","template","attribute-validation","karate-markup"],"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-16T19:17:19.609Z"}