{"record":{"id":"a9462b58c308a762","repo":"elastic/elasticsearch","slug":"test-continued-cannot-be-on-first-snippet-in-a","errorCode":null,"errorMessage":"// TEST[continued] cannot be on first snippet in a file: ${test}","messagePattern":"// TEST\\[continued\\] cannot be on first snippet in a file: (.+?)","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java","lineNumber":245,"sourceCode":"            }\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()) {\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","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/RestTestsFromDocSnippetTask.java#L227-L263","documentation":"In TestBuilder.test, if a snippet is marked // TEST[continued], it must extend a previous test in the same file (previousTest != null AND same path). 'continued' appends to the previous test's YAML section rather than starting a new one, so there must be a prior request to continue. If previousTest is null or in a different file, continuation is impossible.","triggerScenarios":"The first executable snippet in a doc file carries // TEST[continued], or a continued snippet appears in a file whose previous test was in a different file.","commonSituations":"Adding a new // TEST[continued] block at the top of a file before writing the initial request, or moving a continued snippet to a new file without its base request.","solutions":["Ensure a non-continued console request snippet precedes the // TEST[continued] snippet in the same file.","Remove // TEST[continued] from the first snippet if it is meant to be a standalone test."],"exampleFix":"// before — continued is the first snippet\n// CONSOLE\n// TEST[continued]\nGET /_search\n\n// after — add a base request first\n// CONSOLE\nPOST /idx/_doc\n{ \"a\": 1 }\n// CONSOLE\n// TEST[continued]\nGET /idx/_search","handlingStrategy":"validation","validationCode":"// Ensure TEST[continued] is never the first test snippet in a file\nvoid checkContinuedNotFirst(List<SnippetInfo> fileSnippets, String filePath) {\n    boolean seenBase = false;\n    for (SnippetInfo s : fileSnippets) {\n        if (s.continued && !seenBase) {\n            throw new IllegalStateException(\n                \"// TEST[continued] in \" + filePath + \" has no preceding base request\");\n        }\n        if (s.isRequest && !s.continued) seenBase = true;\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write a non-continued console request before any // TEST[continued] snippet in the same file.","When moving snippets between files, ensure a continued snippet's base request travels with it.","Treat a file whose first test snippet is 'continued' as a lint failure."],"tags":["docs","snippet","test-continued","console"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}