quarkusio/quarkus · error · CodestartStructureException

Target file already exists: + targetPath.toString()

Error message

Target file already exists: + targetPath.toString()

What it means

checkTargetDoesNotExist is a fail-fast guard for strategy handlers that must not overwrite files. It throws when the resolved target path already exists on disk. This prevents strategies like 'create-new' from silently clobbering user files.

Source

Thrown at independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/CodestartFileStrategyHandler.java:47

                    new SmartPomMergeCodestartFileStrategyHandler(),
                    new SmartPackageFileStrategyHandler(),
                    new DockerComposeCodestartFileStrategyHandler())
            .collect(Collectors.toMap(CodestartFileStrategyHandler::name, Function.identity()));

    String name();

    void process(Path targetDirectory, String relativePath, List<TargetFile> codestartFiles, Map<String, Object> data)
            throws IOException;

    default void checkNotEmptyCodestartFiles(List<TargetFile> codestartFiles) {
        if (codestartFiles == null || codestartFiles.isEmpty()) {
            throw new CodestartStructureException("codestartFiles must not be null or empty");
        }
    }

    default void checkTargetDoesNotExist(Path targetPath) {
        if (Files.exists(targetPath)) {
            throw new CodestartStructureException(
                    "Target file already exists: " + targetPath.toString());
        }
    }

    default void createDirectories(Path targetPath) throws IOException {
        Files.createDirectories(targetPath.getParent());
    }

    default void writeFile(final Path targetPath, final String content) throws IOException {
        if (!SKIP_FILE_IDENTIFIER.equals(content)) {
            Files.write(targetPath, content.getBytes(StandardCharsets.UTF_8));
        }
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Clean the target directory or delete the conflicting file before regenerating
  2. Use a different target directory for the new project
  3. Choose a conflict strategy that permits overwrite (e.g. override) instead of one that fails on existing targets

Example fix

// before
handler.process(targetDir, "pom.xml", files, data); // pom.xml may exist
// after
Path p = targetDir.resolve("pom.xml");
if (Files.exists(p)) Files.delete(p);
handler.process(targetDir, "pom.xml", files, data);
Defensive patterns

Strategy: validation

Validate before calling

if (Files.exists(targetDir.resolve(relativePath)))
    throw new IllegalStateException("Exists: " + relativePath);

Try / catch

try { generate.generateProject(targetDir); }
catch (CodestartStructureException e) {
    if (e.getMessage().startsWith("Target file already exists:")) { /* clean or relocate */ }
    else throw e;
}

Prevention

When it happens

Trigger: A codestart file strategy that calls checkTargetDoesNotExist runs during generation while a file already exists at targetDirectory/relativePath — typically generating into a directory with pre-existing content.

Common situations: Generating into a non-empty or previously generated directory; renaming files in a codestart so new files collide with old ones; running generation twice without cleaning the output.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/7a47f5381b6eb9c5. Report an issue: GitHub.