{"record":{"id":"0529321158165d60","repo":"karatelabs/karate","slug":"ka-dispatch-trigger-must-be-non-empty-after-got","errorCode":null,"errorMessage":"ka:dispatch trigger must be non-empty after `@`; got `${attributeValue}`","messagePattern":"ka:dispatch trigger must be non-empty after `@`; got `(.+?)`","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/markup/KaDispatchProcessor.java","lineNumber":97,"sourceCode":"        // Split `<dispatched-event> @ <trigger-event>`. The `@`\n        // delimiter is optional; without it the dispatch fires on click\n        // (default, no htmx dependency). With it, the LHS is the CustomEvent\n        // name and the RHS is the DOM/htmx trigger emitted via\n        // `hx-on:<trigger>` (htmx must be loaded on the page).\n        String av = attributeValue.trim();\n        String eventName = av;\n        String triggerOn = null;\n        int at = av.indexOf('@');\n        if (at >= 0) {\n            if (av.lastIndexOf('@') != at) {\n                throw new RuntimeException(\n                        \"ka:dispatch supports a single `event @ trigger` delimiter; got `\"\n                                + attributeValue + \"`\");\n            }\n            eventName = av.substring(0, at).trim();\n            triggerOn = av.substring(at + 1).trim();\n            if (triggerOn.isEmpty()) {\n                throw new RuntimeException(\n                        \"ka:dispatch trigger must be non-empty after `@`; got `\"\n                                + attributeValue + \"`\");\n            }\n        }\n        if (eventName.isEmpty()) {\n            throw new RuntimeException(\n                    \"ka:dispatch requires an event name; got `\"\n                            + attributeValue + \"`\");\n        }\n        MarkupTemplateContext kec = (MarkupTemplateContext) ctx;\n        String detailJson = \"{}\";\n        String vals = tag.getAttributeValue(getDialectPrefix(), VALS);\n        if (vals != null && !vals.isEmpty()) {\n            Object result = kec.evalLocalAsObject(vals);\n            if (result instanceof Map) {\n                detailJson = Json.of(result).toString();\n            } else if (result != null) {\n                logger.warn(\"ka:dispatch ignored ka:vals — did not evaluate to an object: {}\", vals);","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/markup/KaDispatchProcessor.java#L79-L115","documentation":"After splitting ka:dispatch's 'event @ trigger' value on '@', doProcess validates that the trigger substring after the '@' is non-empty and throws a RuntimeException otherwise. An empty trigger gives an unactionable dispatch binding, so the library fails fast with the offending attribute value in the message.","triggerScenarios":"Writing ka:dispatch=\"eventName @\" or \"eventName @   \" (only whitespace after '@'), often from an incomplete edit or a templated value that rendered empty.","commonSituations":"Deleting the trigger name while refactoring; interpolating a variable into the attribute that resolved to empty string; copy-paste truncation.","solutions":["Provide a non-empty trigger name after the '@', e.g. ka:dispatch=\"save @ form-submit\"","If a dynamic trigger, ensure the interpolated value is populated at render time","If no trigger is needed, remove the '@' and write just the event name"],"exampleFix":"<!-- before -->\n<button ka:dispatch=\"save @\"></button>\n<!-- after -->\n<button ka:dispatch=\"save @ form-submit\"></button>","handlingStrategy":"validation","validationCode":"String[] parts = attrValue.split(\"@\", -1); if (parts.length == 2 && parts[1].trim().isEmpty()) throw new IllegalArgumentException(\"empty ka:dispatch trigger: \" + attrValue);","typeGuard":null,"tryCatchPattern":"try { render(template, model); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().contains(\"trigger must be non-empty\")) { log.error(\"bad ka:dispatch: {}\", e.getMessage()); } throw e; }","preventionTips":["Always provide a trigger name after '@' in ka:dispatch","Check interpolated attribute values are non-empty at render time","Remove the '@' entirely when no trigger is intended"],"tags":["markup","attribute-validation","karate-markup","dispatch"],"backgroundTag":"empty-required-field","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"}