{"record":{"id":"e4e5490188655d58","repo":"elastic/elasticsearch","slug":"failed-to-extract-delimiter-for-join-function","errorCode":null,"errorMessage":"Failed to extract delimiter for join function","messagePattern":"Failed to extract delimiter for join function","errorType":"validation","errorClass":"MustacheException","httpStatus":null,"severity":"error","filePath":"modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java","lineNumber":309,"sourceCode":"        static boolean match(String variable) {\n            return CODE.equalsIgnoreCase(variable);\n        }\n    }\n\n    private static class CustomJoinerCode extends JoinerCode {\n\n        private static final Pattern PATTERN = Pattern.compile(\"^\" + CODE + \" delimiter='(.*)'$\");\n\n        CustomJoinerCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String variable) {\n            super(tc, df, mustache, extractDelimiter(variable));\n        }\n\n        private static String extractDelimiter(String variable) {\n            Matcher matcher = PATTERN.matcher(variable);\n            if (matcher.find()) {\n                return matcher.group(1);\n            }\n            throw new MustacheException(\"Failed to extract delimiter for join function\");\n        }\n\n        static boolean match(String variable) {\n            return PATTERN.matcher(variable).matches();\n        }\n    }\n\n    /**\n     * This function encodes a string using the {@link URLEncoder#encode(String, String)} method\n     * with the UTF-8 charset.\n     */\n    private static class UrlEncoderCode extends DefaultMustache {\n\n        private static final String CODE = \"url\";\n        private final Encoder encoder;\n\n        UrlEncoderCode(TemplateContext tc, DefaultMustacheFactory df, Mustache mustache, String variable) {\n            super(tc, df, mustache.getCodes(), variable);","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/CustomMustacheFactory.java#L291-L327","documentation":"Thrown by CustomJoinerCode.extractDelimiter() when the join function's variable string does not match the expected pattern '^join delimiter=\\'(.*)\\'$'. This is a defensive guard: in normal flow, CustomJoinerCode.match() (which uses the same PATTERN with matches()) is checked before the constructor is invoked, so if match() returns true, extractDelimiter should always succeed. This error is essentially unreachable through the standard template compilation path.","triggerScenarios":"Theoretically triggered if CustomJoinerCode is constructed directly with a variable string that doesn't match the pattern. Through normal template compilation, the iterable() visitor method calls CustomJoinerCode.match(variable) first, so only matching variables reach the constructor. This path would only fire if internal code is modified to bypass the match() check.","commonSituations":"Not normally encountered by users. Could surface if a code change introduces a discrepancy between the match() predicate and the extractDelimiter() parsing logic, or if the PATTERN regex is modified inconsistently. If you see this error, it likely indicates a bug in the lang-mustache module.","solutions":["This error should not occur in normal use — report it as a bug if encountered","Ensure you are using a supported join syntax: {{#join delimiter=','}}items{{/join}}","Check for version mismatches if running a patched or custom build of Elasticsearch","Use the simpler {{#join}}items{{/join}} (comma-delimited default) as a workaround"],"exampleFix":"// standard join syntax (should not trigger this error):\n{{#join delimiter='|'}}tags{{/join}}","handlingStrategy":"validation","validationCode":"// Validate join delimiter syntax before submission\nPattern JOIN_PATTERN = Pattern.compile(\"^join delimiter='(.*)'$\");\nif (!JOIN_PATTERN.matcher(variable).matches()) {\n    // use simple {{#join}}var{{/join}} instead\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the standard join delimiter syntax: {{#join delimiter='|'}}items{{/join}}","This error should not occur in normal use — report as bug if seen","Falls back to comma-delimited {{#join}}items{{/join}} if delimiter syntax is problematic"],"tags":["elasticsearch","lang-mustache","join","delimiter","internal"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}