{"record":{"id":"008926de02cbe489","repo":"elastic/elasticsearch","slug":"could-not-write-config-file","errorCode":null,"errorMessage":"Could not write config file: {}","messagePattern":"Could not write config file: (.+?)","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java","lineNumber":1483,"sourceCode":"                    .map(entry -> entry.getKey() + \": \" + entry.getValue())\n                    .collect(Collectors.joining(\"\\n\")),\n                StandardOpenOption.TRUNCATE_EXISTING,\n                StandardOpenOption.CREATE\n            );\n\n            final List<Path> configFiles;\n            try (Stream<Path> stream = Files.list(getDistroDir().resolve(\"config\"))) {\n                configFiles = stream.collect(Collectors.toList());\n            }\n            logToProcessStdout(\"Copying additional config files from distro \" + configFiles);\n            for (Path file : configFiles) {\n                Path dest = configFile.getParent().resolve(file.getFileName());\n                if (Files.exists(dest) == false) {\n                    Files.copy(file, dest);\n                }\n            }\n        } catch (IOException e) {\n            throw new UncheckedIOException(\"Could not write config file: \" + configFile, e);\n        }\n\n        tweakJvmOptions(configFileRoot);\n        LOGGER.info(\"Written config file:{} for {}\", configFile, this);\n    }\n\n    private void tweakJvmOptions(Path configFileRoot) {\n        LOGGER.info(\"Tweak jvm options {}.\", configFileRoot.resolve(\"jvm.options\"));\n        Path jvmOptions = configFileRoot.resolve(\"jvm.options\");\n        try {\n            String content = new String(Files.readAllBytes(jvmOptions));\n            Map<ReplacementKey, String> expansions = jvmOptionExpansions();\n            for (var entry : expansions.entrySet()) {\n                ReplacementKey replacement = entry.getKey();\n                String key = replacement.key();\n                if (content.contains(key) == false) {\n                    key = replacement.fallback();\n                    if (content.contains(key) == false) {","sourceCodeStart":1465,"sourceCodeEnd":1501,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java#L1465-L1501","documentation":"Thrown in createConfiguration() as the catch-all for any IOException during writing of the elasticsearch.yml config file AND copying additional config files from the distro's config/ dir. The try block covers Files.writeString(configFile, ...), Files.list(getDistroDir().resolve(\"config\")), and Files.copy for each extra config file.","triggerScenarios":"Files.writeString fails (disk full, permissions, parent dir missing), or Files.list/Files.copy on the distro config dir fails (distro dir not extracted, config subdir missing, antivirus blocks the copy).","commonSituations":"Distro extraction was incomplete (no config/ subdir under the extracted distribution); the build/testclusters working dir is on a read-only or full volume; antivirus blocks writing the generated yml; a stale file handle on Windows prevents overwriting configFile.","solutions":["Free disk space and check write permissions on the testclusters working dir.","Re-extract the distribution: delete build/testclusters/<id>/distro and the extracted-distribution cache, then re-run.","Confirm getDistroDir()/config exists and is populated — if not, the distro build task failed silently upstream.","On Windows, close any process holding the config file and add AV exclusions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (Files.notExists(configFile.getParent())) {\n    Files.createDirectories(configFile.getParent());\n}\nif (Files notExists(getDistroDir().resolve(\"config\"))) {\n    throw new IllegalStateException(\"distro config dir missing — re-extract\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Files.writeString(configFile, ...);\n} catch (IOException e) {\n    throw new UncheckedIOException(\"Could not write config file: \" + configFile, e);\n}","preventionTips":["Keep the testclusters working dir on a writable, non-full volume.","Re-extract the distro if its config/ subdir is missing.","On Windows, add AV exclusions and close stale file handles."],"tags":["testclusters","config","io","distribution"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}