elastic/elasticsearch · error · GradleException

Yaml rest specs ({asciidocFile} and {mdxFile}) are not equal

Error message

Yaml rest specs ({asciidocFile} and {mdxFile}) are not equal, different line count

What it means

Thrown by the same asciidoc/mdx parity check after both YAML files are read. If the asciidoc spec and its mdx counterpart have a different number of lines, the two cannot be byte-equivalent, so the build fails listing both file paths. This catches migrations where a line was dropped or duplicated when copying the spec.

Source

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

        public void finishLastTest() {
            if (current != null) {
                current.close();
                current = null;
            }
        }
    }

    private void assertEqualTestSnippetFromMigratedDocs() {
        getTestRoot().getAsFileTree().matching(patternSet -> { patternSet.include("**/*asciidoc.yml"); }).forEach(asciidocFile -> {
            File mdxFile = new File(asciidocFile.getAbsolutePath().replace(".asciidoc.yml", ".mdx.yml"));
            if (mdxFile.exists() == false) {
                throw new InvalidUserDataException("Couldn't find the corresponding mdx file for " + asciidocFile.getAbsolutePath());
            }
            try {
                List<String> asciidocLines = Files.readAllLines(asciidocFile.toPath());
                List<String> mdxLines = Files.readAllLines(mdxFile.toPath());
                if (asciidocLines.size() != mdxLines.size()) {
                    throw new GradleException(
                        "Yaml rest specs ("
                            + asciidocFile.toPath()
                            + " and "
                            + mdxFile.getAbsolutePath()
                            + ") are not equal, different line count"
                    );

                }
                for (int i = 0; i < asciidocLines.size(); i++) {
                    if (asciidocLines.get(i)
                        .replaceAll("line_\\d+", "line_0")
                        .equals(mdxLines.get(i).replaceAll("line_\\d+", "line_0")) == false) {
                        throw new GradleException(
                            "Yaml rest specs ("
                                + asciidocFile.toPath()
                                + " and "
                                + mdxFile.getAbsolutePath()
                                + ") are not equal, difference on line: "

View on GitHub (pinned to db6a809a66)

Solutions

  1. Open both files side by side (the paths are in the message) and reconcile the line counts so they match.
  2. Diff the two files with `diff <asciidoc> <mdx>` to see exactly which lines were added or removed.
  3. Re-generate the mdx file from the asciidoc source using the project's migration tooling if available, rather than editing by hand.

Example fix

# before: asciidoc.yml has 12 lines, mdx.yml has 11
# after: add the missing line to mdx.yml so both have 12
Defensive patterns

Strategy: validation

Validate before calling

// Before building, assert line counts match:
// long a = Files.lines(asciidoc.toPath()).count();
// long m = Files.lines(mdx.toPath()).count();
// if (a != m) fail("line count mismatch: " + a + " vs " + m);

Prevention

When it happens

Trigger: Both `<name>.asciidoc.yml` and `<name>.mdx.yml` exist but their line counts differ. Typically happens when hand-porting a spec and missing or duplicating a request/response line.

Common situations: A merge conflict resolved by taking one side's line count; a copy-paste that duplicated a stanza; a find/replace that collapsed two lines into one or vice-versa.

Related errors


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