{"record":{"id":"eb861f1a892cca0e","repo":"elastic/elasticsearch","slug":"duplicated-snippet-name-testname-test","errorCode":null,"errorMessage":"Duplicated snippet name '${testName}': ${test}","messagePattern":"Duplicated snippet name '(.+?)': (.+?)","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java","lineNumber":257,"sourceCode":"            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()) {\n                    throw new InvalidUserDataException(\"// TEST[continued] \" + \"cannot immediately follow // TESTSETUP: \" + test);\n                }\n                if (previousTest != null && previousTest.testSetup()) {\n                    throw new InvalidUserDataException(\"// TEST[continued] \" + \"cannot immediately follow // TEARDOWN: \" + test);\n                }\n            } else {\n                current.println(\"---\");\n                if (test.name() != null && test.name().isBlank() == false) {\n                    if (names.add(test.name()) == false) {\n                        throw new InvalidUserDataException(\"Duplicated snippet name '\" + test.name() + \"': \" + test);\n                    }\n                    current.println(\"\\\"\" + test.name() + \"\\\":\");\n                } else {\n                    current.println(\"\\\"line_\" + test.start() + \"\\\":\");\n                }\n                /* The Elasticsearch test runner doesn't support quite a few\n                 * constructs unless we output this skip. We don't know if\n                 * we're going to use these constructs, but we might so we\n                 * output the skip just in case. */\n                current.println(\"  - skip:\");\n                current.println(\"      features:\");\n                current.println(\"        - default_shards\");\n                current.println(\"        - stash_in_key\");\n                current.println(\"        - stash_in_path\");\n                current.println(\"        - stash_path_replace\");\n                current.println(\"        - warnings\");\n            }\n            if (test.skip() != null) {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java#L239-L275","documentation":"TestBuilder.names is a per-file Set of explicit snippet names. When a non-continued test snippet has a name (from // TEST[name]) and names.add returns false, the name was already registered in this file. Duplicate names break the generated YAML test file because each test is keyed by its name.","triggerScenarios":"Two console snippets in the same doc file both carry // TEST[myTest] (or the mdx equivalent) with the same name string.","commonSituations":"Copy-pasting a snippet and forgetting to rename it; merging two files that happened to use the same snippet name.","solutions":["Rename the duplicate so each // TEST[name] in a file is unique.","If the snippets are genuinely the same test split across continued blocks, use // TEST[continued] on the subsequent ones instead of repeating the name."],"exampleFix":"// before — two snippets share 'search'\n// CONSOLE\n// TEST[search]\nGET /idx/_search\n// CONSOLE\n// TEST[search]\nGET /idx2/_search\n\n// after — unique names\n// CONSOLE\n// TEST[search_idx]\nGET /idx/_search\n// CONSOLE\n// TEST[search_idx2]\nGET /idx2/_search","handlingStrategy":"validation","validationCode":"// Ensure snippet names are unique within each doc file\nimport java.util.HashSet;\nimport java.util.Set;\n\nvoid checkUniqueNames(List<SnippetInfo> fileSnippets, String filePath) {\n    Set<String> seen = new HashSet<>();\n    for (SnippetInfo s : fileSnippets) {\n        if (s.name != null && !s.name.isBlank()) {\n            if (!seen.add(s.name)) {\n                throw new IllegalStateException(\n                    \"Duplicate snippet name '\" + s.name + \"' in \" + filePath);\n            }\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give every named snippet a unique name within its file.","For multi-step tests, use // TEST[continued] on subsequent fragments instead of repeating the name.","When copy-pasting a snippet, always rename it."],"tags":["docs","snippet","naming","yaml","console"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}