{"record":{"id":"0022cb305bcd159e","repo":"elastic/elasticsearch","slug":"snippet-use-source-console-instead-of","errorCode":null,"errorMessage":"${snippet}: Use `[source,console]` instead of `// CONSOLE`.","messagePattern":"(.+?): Use `\\[source,console\\]` instead of `// CONSOLE`\\.","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java","lineNumber":229,"sourceCode":"                return;\n            }\n            if (snippet.testTearDown()) {\n                testTearDown(snippet);\n                previousTest = snippet;\n                return;\n            }\n            if (snippet.testResponse() || snippet.language().equals(\"console-result\")) {\n                if (previousTest == null) {\n                    throw new InvalidUserDataException(snippet + \": No paired previous test\");\n                }\n                if (previousTest.path().equals(snippet.path()) == false) {\n                    throw new InvalidUserDataException(snippet + \": Result can't be first in file\");\n                }\n                response(snippet);\n                return;\n            }\n            if ((\"js\".equals(snippet.language())) && snippet.console() != null && snippet.console()) {\n                throw new InvalidUserDataException(snippet + \": Use `[source,console]` instead of `// CONSOLE`.\");\n            }\n            if (snippet.test() || snippet.language().equals(\"console\")) {\n                test(snippet);\n                previousTest = snippet;\n            }\n            // Must be an unmarked snippet....\n        }\n\n        private void test(Snippet test) {\n            setupCurrent(test);\n\n            if (test.continued()) {\n                /* Catch some difficult to debug errors with // TEST[continued]\n                 * and throw a helpful error message. */\n                if (previousTest == null || previousTest.path().equals(test.path()) == false) {\n                    throw new InvalidUserDataException(\"// TEST[continued] \" + \"cannot be on first snippet in a file: \" + test);\n                }\n                if (previousTest != null && previousTest.testSetup()) {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java#L211-L247","documentation":"handleSnippet checks: if the snippet language is 'js' AND snippet.console() is explicitly true, it throws. The 'js' language with a '// CONSOLE' marker is a deprecated combination — the preferred way to mark an executable console request is the [source,console] block attribute, not a 'js' block with a CONSOLE comment.","triggerScenarios":"An asciidoc/mdx source block uses language 'js' and also carries the '// CONSOLE' marker (snippet.console() returns true).","commonSituations":"Legacy doc snippets that used 'js' + '// CONSOLE' before the 'console' language was introduced; copy-pasting old examples into new docs.","solutions":["Change the source block from [source,js] with '// CONSOLE' to [source,console] and remove the '// CONSOLE' marker.","If the block is genuinely a JS example (not a console request), remove the '// CONSOLE' marker so snippet.console() is false."],"exampleFix":"// before (asciidoc)\n[source,js]\n----\n// CONSOLE\nGET /_search\n----\n\n// after\n[source,console]\n----\nGET /_search\n----","handlingStrategy":"validation","validationCode":"// Detect deprecated 'js' + '// CONSOLE' combination\nvoid checkConsoleLanguage(SnippetInfo s) {\n    if (\"js\".equals(s.language) && Boolean.TRUE.equals(s.consoleFlag)) {\n        throw new IllegalStateException(\n            \"Snippet \" + s.path + \" uses 'js' + '// CONSOLE'. Use [source,console] instead.\");\n    }\n}","typeGuard":"boolean isCanonicalConsoleSnippet(String language, Boolean consoleFlag) {\n    return !(\"js\".equals(language) && Boolean.TRUE.equals(consoleFlag));\n}","tryCatchPattern":null,"preventionTips":["Use [source,console] for executable console requests; never combine 'js' with '// CONSOLE'.","Reserve 'js' for genuine JavaScript examples (no '// CONSOLE' marker).","grep for '// CONSOLE' in docs and convert each to the [source,console] block style."],"tags":["docs","snippet","console","language","deprecation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}