{"record":{"id":"bbf64a3047812d50","repo":"elastic/elasticsearch","slug":"error-parsing-snippet-in-filename-at-line-linen","errorCode":null,"errorMessage":"Error parsing snippet in {fileName} at line {lineNumber}","messagePattern":"Error parsing snippet in (.+?) at line (.+?)","errorType":"exception","errorClass":"SnippetParserException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/SnippetParser.java","lineNumber":81,"sourceCode":"        try (Stream<String> lines = Files.lines(docFile.toPath(), StandardCharsets.UTF_8)) {\n            List<String> linesList = lines.toList();\n            parseLines(docFile, linesList, snippets);\n        } catch (IOException e) {\n            throw new SnippetParserException(\"Failed to parse file \" + docFile, e);\n        } finally {\n            this.currentPath = null;\n            this.snippetBuilder = null;\n        }\n        return snippets;\n    }\n\n    void parseLines(File file, List<String> linesList, List<Snippet> snippets) {\n        for (int lineNumber = 0; lineNumber < linesList.size(); lineNumber++) {\n            String line = linesList.get(lineNumber);\n            try {\n                parseLine(snippets, lineNumber, line);\n            } catch (InvalidUserDataException e) {\n                throw new SnippetParserException(file, lineNumber, e);\n            }\n        }\n        fileParsingFinished(snippets);\n    }\n\n    protected void handleCommons(List<Snippet> snippets, String line) {\n        if (consoleHandled(line, snippetBuilder)) {\n            return;\n        }\n        if (testHandled(line, snippetBuilder)) {\n            return;\n        }\n        if (testResponseHandled(line, snippetBuilder)) {\n            return;\n        }\n        if (line.matches(getTestSetupRegex())) {\n            snippetBuilder.withTestSetup(true);\n            return;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/SnippetParser.java#L63-L99","documentation":"Thrown by SnippetParser.parseLines() when an individual line's parseLine() call raises an InvalidUserDataException (any of the snippet-validation errors like missing language, unpaired CONSOLE/TEST, etc.). The wrapper re-throws it as a SnippetParserException that carries the source file and the 0-based line number, converting a generic validation error into one pinpointed to its doc location. Note: the line number reported is the internal 0-based index from the loop.","triggerScenarios":"Any of the snippet-level InvalidUserDataException conditions (errors 204, 205, 209, 210, 211, 212, 213, 214, 215) fires while parsing a specific line of a doc file. parseLines catches it and wraps it with file + line context so the developer sees where in the document the problem is.","commonSituations":"A doc author writes a malformed snippet marker anywhere in a documentation file; the underlying cause is one of the sibling errors in this list — this wrapper just adds file:line context.","solutions":["Read the wrapped cause (the original InvalidUserDataException message) to identify which snippet-level rule was violated.","Open the reported file at the reported line number (remember it may be 0-based internally, but the message includes the index) and fix the underlying snippet syntax.","Cross-reference the cause text with the specific sibling error in this catalog (e.g. 'TESTRESPONSE not paired' → error 209) for the targeted fix."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// This is a wrapper around sibling snippet errors — catch SnippetParserException\n// and read getCause() to identify and fix the underlying InvalidUserDataException.","preventionTips":["Always read the wrapped cause — the real rule violation is in the inner exception.","Use the reported file:line to jump straight to the offending snippet.","Fix the underlying sibling error (204/205/209-215) rather than treating this as a separate problem."],"tags":["docs","snippet-tests","build","wrapper"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}