{"record":{"id":"46b7f703086ea8f3","repo":"elastic/elasticsearch","slug":"invalid-block-quote-starting-at-start-in-bod","errorCode":null,"errorMessage":"Invalid block quote starting at ${start} in:\n${body}","messagePattern":"Invalid block quote starting at (.+?) in:\n(.+?)","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java","lineNumber":139,"sourceCode":"     * contain newlines and {@code \"} without the normal JSON escaping.\n     * This has to add it.\n     */\n    @PackageScope\n    static String replaceBlockQuote(String body) {\n        int start = body.indexOf(\"\\\"\\\"\\\"\");\n        if (start < 0) {\n            return body;\n        }\n        /*\n         * 1.3 is a fairly wild guess of the extra space needed to hold\n         * the escaped string.\n         */\n        StringBuilder result = new StringBuilder((int) (body.length() * 1.3));\n        int startOfNormal = 0;\n        while (start >= 0) {\n            int end = body.indexOf(\"\\\"\\\"\\\"\", start + 3);\n            if (end < 0) {\n                throw new InvalidUserDataException(\"Invalid block quote starting at \" + start + \" in:\\n\" + body);\n            }\n            result.append(body.substring(startOfNormal, start));\n            result.append('\"');\n            result.append(body.substring(start + 3, end).replace(\"\\\"\", \"\\\\\\\"\").replace(\"\\n\", \"\\\\n\"));\n            result.append('\"');\n            startOfNormal = end + 3;\n            start = body.indexOf(\"\\\"\\\"\\\"\", startOfNormal);\n        }\n        result.append(body.substring(startOfNormal));\n        return result.toString();\n    }\n\n    private class TestBuilder {\n        /**\n         * These languages aren't supported by the syntax highlighter so we\n         * shouldn't use them.\n         */\n        private static final List BAD_LANGUAGES = List.of(\"json\", \"javascript\");","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java#L121-L157","documentation":"replaceBlockQuote converts Kibana-style triple-quote ('\"\"\"') delimited strings into standard escaped JSON strings. It finds the opening '\"\"\"' and then searches for the closing '\"\"\"'; if the closing delimiter is never found (indexOf returns -1) the string is malformed and cannot be safely converted, so it throws with the byte offset of the unmatched opening quote.","triggerScenarios":"A CONSOLE snippet body or a console-result response contains a '\"\"\"' block-quote opener but no corresponding closing '\"\"\"', producing an unbalanced delimiter.","commonSituations":"Manually editing a JSON body in a doc snippet and deleting the closing '\"\"\"' by accident, or copy-pasting only part of a block-quoted string. The start offset in the message points at the orphaned opening delimiter.","solutions":["Find the '\"\"\"' at the reported 'start' offset and add the matching closing '\"\"\"' after the string content.","If block-quoting is not needed, remove the '\"\"\"' entirely and use standard JSON string escaping (\\\" for quotes, \\n for newlines).","Validate that every '\"\"\"' in the snippet body is paired by counting occurrences (must be even)."],"exampleFix":"// before — unbalanced block quote\nGET /_search\n\"\"\"\n{ \"query\": { \"match_all\": {} } }\n\n// after — close the block quote\nGET /_search\n\"\"\"\n{ \"query\": { \"match_all\": {} } }\n\"\"\"","handlingStrategy":"validation","validationCode":"// Verify triple-quote delimiters are balanced before building\nvoid checkBlockQuotes(String body, String snippetPath) {\n    int count = 0, idx = -1;\n    while ((idx = body.indexOf(\"\\\"\\\"\\\"\", idx + 1)) != -1) count++;\n    if (count % 2 != 0) {\n        throw new IllegalStateException(\n            \"Unbalanced '\\\"\\\"\\\"' block quote in \" + snippetPath\n            + \": found \" + count + \" delimiters (must be even)\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Count '\"\"\"' occurrences in a snippet body — they must be even.","Prefer standard JSON escaping (\\\", \\n) over block quotes for short strings.","When editing a block-quoted body, keep the closing '\"\"\"' visible while editing."],"tags":["docs","block-quote","json","console","snippet"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}