{"record":{"id":"02a62eed18f1c8a5","repo":"quarkusio/quarkus","slug":"target-file-already-exists-targetpath-tostring-02a62e","errorCode":null,"errorMessage":"Target file already exists: + targetPath.toString()","messagePattern":"Target file already exists: \\+ targetPath\\.toString\\(\\)","errorType":"exception","errorClass":"CodestartStructureException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/DockerComposeCodestartFileStrategyHandler.java","lineNumber":50,"sourceCode":"            writeFile(targetDirectory.resolve(filename), targetFile.getContent());\n\n            includes.add(filename);\n        }\n        data.put(NAME, includes);\n\n        StringBuilder content = new StringBuilder(INCLUDE_LINE_IDENTIFIER);\n        for (String include : includes) {\n            content.append(\"  - \").append(include).append(\"\\n\");\n        }\n\n        final Path targetPath = targetDirectory.resolve(\"docker-compose.yml\");\n        writeFile(targetPath, content.toString());\n    }\n\n    @Override\n    public void writeFile(final Path targetPath, final String content) throws IOException {\n        if (Files.exists(targetPath) && !Files.readString(targetPath).startsWith(INCLUDE_LINE_IDENTIFIER)) {\n            throw new CodestartStructureException(\n                    \"Target file already exists: \" + targetPath.toString());\n        }\n\n        Files.writeString(targetPath, content);\n    }\n\n}\n","sourceCodeStart":32,"sourceCodeEnd":58,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/DockerComposeCodestartFileStrategyHandler.java#L32-L58","documentation":"DockerComposeCodestartFileStrategyHandler throws CodestartStructureException when it is about to write a docker-compose related file but the target file already exists on disk and does not begin with the include-line marker (#/quarkus-include or similar). Codestarts merge docker-compose files via include lines; an existing file that is not an include-merged file would be silently overwritten, so the library refuses. This protects user-authored docker-compose content from being clobbered by a codestart generation.","triggerScenarios":"Running a codestart that includes a docker-compose strategy when targetDirectory already contains a docker-compose.yml (or similar target file) whose content does not start with the include-line identifier.","commonSituations":"Re-running `quarkus create` or codestart application into a project where docker-compose.yml was previously generated by hand or by an older codestart version that predates the include-line merge format.","solutions":["Delete or rename the existing docker-compose file at targetPath so the codestart can generate a fresh one","Add the expected include-line identifier as the first line of the existing file so the merge strategy treats it as a merged file","Back up the existing compose file, let the codestart write a new one, and manually re-apply your customizations"],"exampleFix":"// before\ndocker-compose.yml:\nservices:\n  db: ...\n\n// after\ndocker-compose.yml:\n#/quarkus-include\ninclude: [docker-compose.generated.yml]\nservices:\n  db: ...","handlingStrategy":"validation","validationCode":"Path targetPath = targetDir.resolve(\"docker-compose.yml\");\nif (Files.exists(targetPath) && !Files.readString(targetPath).startsWith(INCLUDE_LINE_IDENTIFIER)) {\n    throw new IllegalStateException(\"Existing non-merged docker-compose file at \" + targetPath + \" — remove or add include line first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    handler.process(targetDir, relativePath, files, data);\n} catch (CodestartStructureException e) {\n    if (e.getMessage().startsWith(\"Target file already exists\")) {\n        // prompt user to remove/rename the existing file or merge manually\n    } else throw e;\n}","preventionTips":["Check for existing docker-compose files before applying codestarts to an existing project","Keep generated compose files merged via the include-line format so re-runs succeed","Run codestart generation in a clean directory and port customizations afterwards"],"tags":["codestarts","file-conflict","docker-compose"],"backgroundTag":"target-file-already-exists","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}