elastic/elasticsearch · error · InvalidUserDataException

Extra content ${message} ('${cutOutNoNl}') matching [${patte

Error message

Extra content ${message} ('${cutOutNoNl}') matching [${pattern}]: ${content}

What it means

ParsingUtils.parse walks the snippet content with a regex, tracking how far it has consumed. extra_content is called when characters exist between the current offset and the next match (or after the last match) that the pattern did not account for — i.e. the snippet body has stray text that is not a valid CONSOLE request, comment, or startyaml/endyaml block.

Source

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

 */

package org.elasticsearch.gradle.internal.doc;

import org.gradle.api.InvalidUserDataException;

import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ParsingUtils {

    static void extraContent(String message, String content, int offset, String pattern) {
        StringBuilder cutOut = new StringBuilder();
        cutOut.append(content.substring(offset - 6, offset));
        cutOut.append('*');
        cutOut.append(content.substring(offset, Math.min(offset + 5, content.length())));
        String cutOutNoNl = cutOut.toString().replace("\n", "\\n");
        throw new InvalidUserDataException("Extra content " + message + " ('" + cutOutNoNl + "') matching [" + pattern + "]: " + content);
    }

    /**
     * Repeatedly match the pattern to the string, calling the closure with the
     * matchers each time there is a match. If there are characters that don't
     * match then blow up. If the closure takes two parameters then the second
     * one is "is this the last match?".
     */
    static void parse(String content, String pattern, BiConsumer<Matcher, Boolean> testHandler) {
        if (content == null) {
            return; // Silly null, only real stuff gets to match!
        }
        Matcher m = Pattern.compile(pattern).matcher(content);
        int offset = 0;
        while (m.find()) {
            if (m.start() != offset) {
                extraContent("between [$offset] and [${m.start()}]", content, offset, pattern);
            }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Read the 'cutOutNoNl' context in the message: it shows the characters around offset (* marks the boundary) — fix the text at that position.
  2. Ensure every line in the snippet is either an HTTP method + path, a continuation body line, a '#' comment, or inside startyaml/endyaml.
  3. Remove stray whitespace-only or prose lines from the snippet block.

Example fix

// before — stray line breaks the grammar
GET /_search
{ "query": { "match_all": {} } }
this is prose

// after — remove the prose line
GET /_search
{ "query": { "match_all": {} } }
Defensive patterns

Strategy: validation

Validate before calling

// Lint a console snippet body for stray non-conforming lines
import java.util.regex.Pattern;

private static final Pattern LINE_OK = Pattern.compile(
    "^(GET|PUT|POST|HEAD|OPTIONS|DELETE)\\s+\\S.*$|^#.*$|^startyaml$|^endyaml$|^\\{.*$|^\\}.*$|^\\[.*$|^\".*$|^\\s.*$|^");

void checkSnippetBody(String contents) {
    int lineNo = 0;
    for (String line : contents.split("\\R")) {
        lineNo++;
        if (!LINE_OK.matcher(line).matches()) {
            throw new IllegalStateException(
                "Line " + lineNo + " may break CONSOLE parser: '" + line + "'");
        }
    }
}

Prevention

When it happens

Trigger: A CONSOLE snippet in an asciidoc/mdx doc contains a line that does not start with an HTTP method (GET/PUT/POST/HEAD/OPTIONS/DELETE), is not a comment (#), and is not part of a request body line following a method line — for example a typo'd method like 'GETT /_search' or a stray prose line mixed into the snippet.

Common situations: Editing a documentation snippet and accidentally leaving a blank-but-with-whitespace line in a position the grammar doesn't expect, pasting a multi-line JSON body without a preceding method line, or a line that starts with a keyword the badBody regex excludes (like 'POST' misspelled as 'P0ST').

Related errors


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