elastic/elasticsearch · error · InvalidUserDataException

${snippet}: Use `[source,console]` instead of `// CONSOLE`.

Error message

${snippet}: Use `[source,console]` instead of `// CONSOLE`.

What it means

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.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java:229

                return;
            }
            if (snippet.testTearDown()) {
                testTearDown(snippet);
                previousTest = snippet;
                return;
            }
            if (snippet.testResponse() || snippet.language().equals("console-result")) {
                if (previousTest == null) {
                    throw new InvalidUserDataException(snippet + ": No paired previous test");
                }
                if (previousTest.path().equals(snippet.path()) == false) {
                    throw new InvalidUserDataException(snippet + ": Result can't be first in file");
                }
                response(snippet);
                return;
            }
            if (("js".equals(snippet.language())) && snippet.console() != null && snippet.console()) {
                throw new InvalidUserDataException(snippet + ": Use `[source,console]` instead of `// CONSOLE`.");
            }
            if (snippet.test() || snippet.language().equals("console")) {
                test(snippet);
                previousTest = snippet;
            }
            // Must be an unmarked snippet....
        }

        private void test(Snippet test) {
            setupCurrent(test);

            if (test.continued()) {
                /* Catch some difficult to debug errors with // TEST[continued]
                 * and throw a helpful error message. */
                if (previousTest == null || previousTest.path().equals(test.path()) == false) {
                    throw new InvalidUserDataException("// TEST[continued] " + "cannot be on first snippet in a file: " + test);
                }
                if (previousTest != null && previousTest.testSetup()) {

View on GitHub (pinned to db6a809a66)

Solutions

  1. Change the source block from [source,js] with '// CONSOLE' to [source,console] and remove the '// CONSOLE' marker.
  2. If the block is genuinely a JS example (not a console request), remove the '// CONSOLE' marker so snippet.console() is false.

Example fix

// before (asciidoc)
[source,js]
----
// CONSOLE
GET /_search
----

// after
[source,console]
----
GET /_search
----
Defensive patterns

Strategy: validation

Validate before calling

// Detect deprecated 'js' + '// CONSOLE' combination
void checkConsoleLanguage(SnippetInfo s) {
    if ("js".equals(s.language) && Boolean.TRUE.equals(s.consoleFlag)) {
        throw new IllegalStateException(
            "Snippet " + s.path + " uses 'js' + '// CONSOLE'. Use [source,console] instead.");
    }
}

Type guard

boolean isCanonicalConsoleSnippet(String language, Boolean consoleFlag) {
    return !("js".equals(language) && Boolean.TRUE.equals(consoleFlag));
}

Prevention

When it happens

Trigger: An asciidoc/mdx source block uses language 'js' and also carries the '// CONSOLE' marker (snippet.console() returns true).

Common situations: Legacy doc snippets that used 'js' + '// CONSOLE' before the 'console' language was introduced; copy-pasting old examples into new docs.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/0022cb305bcd159e. Report an issue: GitHub.