{"record":{"id":"d4d0f272dabdd249","repo":"elastic/elasticsearch","slug":"can-t-be-both-console-and-notconsole","errorCode":null,"errorMessage":"Can't be both CONSOLE and NOTCONSOLE","messagePattern":"Can't be both CONSOLE and NOTCONSOLE","errorType":"validation","errorClass":"InvalidUserDataException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/SnippetParser.java","lineNumber":230,"sourceCode":"                    if (m.group(9) != null) {\n                        snippetBuilder.withSkipShardsFailures(true);\n                        return;\n                    }\n                    throw new InvalidUserDataException(\"Invalid test marker: \" + line);\n                });\n            }\n            return true;\n        }\n        return false;\n    }\n\n    protected boolean consoleHandled(String line, SnippetBuilder snippet) {\n        if (line.matches(getConsoleRegex())) {\n            if (snippetBuilder == null) {\n                throw new InvalidUserDataException(\"CONSOLE not paired with a snippet\");\n            }\n            if (snippetBuilder.consoleDefined()) {\n                throw new InvalidUserDataException(\"Can't be both CONSOLE and NOTCONSOLE\");\n            }\n            snippetBuilder.withConsole(Boolean.TRUE);\n            return true;\n        } else if (line.matches(getNotconsoleRegex())) {\n            if (snippet == null) {\n                throw new InvalidUserDataException(\"NOTCONSOLE not paired with a snippet\");\n            }\n            if (snippetBuilder.consoleDefined()) {\n                throw new InvalidUserDataException(\"Can't be both CONSOLE and NOTCONSOLE\");\n            }\n            snippet.withConsole(Boolean.FALSE);\n            return true;\n        }\n        return false;\n    }\n\n    protected abstract String getTestSetupRegex();\n","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/doc/SnippetParser.java#L212-L248","documentation":"Thrown by SnippetParser.consoleHandled() in the CONSOLE branch when a `// CONSOLE` directive is processed but snippetBuilder.consoleDefined() is already true — meaning the snippet has already been marked CONSOLE or NOTCONSOLE. A snippet can be either console or not-console, not both; setting CONSOLE twice (or after NOTCONSOLE) is contradictory.","triggerScenarios":"A single snippet has two console-status directives applied to it: either two `// CONSOLE` lines, or a `// CONSOLE` after a `// NOTCONSOLE`. The CONSOLE branch checks consoleDefined() before setting.","commonSituations":"A copy-paste duplicated the CONSOLE directive within one snippet; a snippet was edited and both CONSOLE and NOTCONSOLE directives were left on it; a migration tool emitted both markers.","solutions":["Inspect the snippet's directives and keep only one console-status marker (either CONSOLE or NOTCONSOLE, not both, and not duplicated).","Remove the redundant second directive so consoleDefined() is false when the surviving one is processed."],"exampleFix":"// before:\n// CONSOLE\n// NOTCONSOLE\n----\nGET /_search\n----\n// after:\n// CONSOLE\n----\nGET /_search\n----","handlingStrategy":"validation","validationCode":"// Before building, for each snippet assert consoleDefined() is set at most once (no duplicate/conflicting CONSOLE/NOTCONSOLE).","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep at most one console-status directive (CONSOLE or NOTCONSOLE) per snippet.","After editing snippet markers, re-read the block to confirm no duplicates remain."],"tags":["docs","snippet-tests","validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}