{"record":{"id":"7d980a4868ed649f","repo":"elastic/elasticsearch","slug":"capturing-output-was-not-enabled-use-name-getc","errorCode":null,"errorMessage":"Capturing output was not enabled. Use ${name}.getCapturedOutput.set(true) to enable output capturing.","messagePattern":"Capturing output was not enabled\\. Use (.+?)\\.getCapturedOutput\\.set\\(true\\) to enable output capturing\\.","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java","lineNumber":241,"sourceCode":"            });\n        } catch (Exception e) {\n            if (output.size() != 0) {\n                LOGGER.error(\"Exec output and error:\");\n                NEWLINE.splitAsStream(output.toString(StandardCharsets.UTF_8)).forEach(s -> LOGGER.error(\"| \" + s));\n            }\n            throw e;\n        }\n    }\n\n    @Override\n    public WorkResult delete(Object... objects) {\n        return fileSystemOperations.delete(d -> d.delete(objects));\n    }\n\n    @Internal\n    public String getOutput() {\n        if (getCaptureOutput().get() == false) {\n            throw new GradleException(\n                \"Capturing output was not enabled. Use \" + getName() + \".getCapturedOutput.set(true) to enable output capturing.\"\n            );\n        }\n        return output;\n    }\n\n    private static class IndentingOutputStream extends OutputStream {\n\n        public final byte[] indent;\n        private final OutputStream delegate;\n\n        IndentingOutputStream(OutputStream delegate, Object version) {\n            this.delegate = delegate;\n            indent = (\" [\" + version + \"] \").getBytes(StandardCharsets.UTF_8);\n        }\n\n        @Override\n        public void write(int b) throws IOException {","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java#L223-L259","documentation":"LoggedExec.getOutput() throws when a caller requests the captured process output but getCaptureOutput() was left at its default false. Output capturing is opt-in because it buffers the entire process output in memory (a ByteArrayOutputStream), which is wasteful when only console logging is needed. The message names the task and the exact property to flip.","triggerScenarios":"Calling task.getOutput() on a LoggedExec task whose getCaptureOutput().get() is false (the convention default). The check runs at the point of retrieval, not at task execution, so the task may have already completed successfully before this fires.","commonSituations":"A downstream task or build script reads loggedExec.getOutput() to parse a command's result without first enabling capture; refactoring code that previously used Gradle's standard Exec (which captures by default) to LoggedExec (which does not).","solutions":["Set getCaptureOutput().set(true) on the LoggedExec task configuration before reading getOutput().","Note that captureOutput is incompatible with indentingConsoleOutput (see error 26) — ensure only one is set.","If you only need the output for logging, do not call getOutput() at all; let LoggedExec log it on failure."],"exampleFix":"// before\nloggedExec {\n  commandLine 'some-tool'\n}\n// later: def out = loggedExec.getOutput() // throws\n\n// after\nloggedExec {\n  commandLine 'some-tool'\n  captureOutput = true\n}\ndef out = loggedExec.getOutput()","handlingStrategy":"validation","validationCode":"if (!loggedExec.getCaptureOutput().get()) {\n    throw new IllegalStateException(\"Enable \" + loggedExec.getName() + \".captureOutput before calling getOutput()\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set captureOutput=true when you intend to call getOutput() later.","Remember captureOutput is incompatible with indentingConsoleOutput.","Refrain from calling getOutput() if you only need console logging."],"tags":["gradle","build-tools","exec","configuration-validation"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}