{"record":{"id":"b0dbd6290307d0b8","repo":"quarkusio/quarkus","slug":"target-directory-already-exists-path","errorCode":null,"errorMessage":"Target directory already exists: ${path}","messagePattern":"Target directory already exists: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java","lineNumber":150,"sourceCode":"            throw new IllegalArgumentException(name + \" is not a valid class name\");\n        }\n        return name;\n    }\n\n    public static String checkPackageName(String name) {\n        if (!SourceVersion.isName(name)) { // checks for valid identifiers & use of keywords\n            throw new IllegalArgumentException(name + \" is not a valid package name\");\n        }\n        return name;\n    }\n\n    public static Path checkProjectRootPath(Path outputPath, String name) {\n        requireNonNull(name, \"Must specify project name\");\n        requireNonNull(outputPath, \"Must specify output path\");\n\n        Path projectRootPath = outputPath.resolve(name);\n        if (projectRootPath.toFile().exists()) {\n            throw new IllegalArgumentException(\n                    \"Target directory already exists: \" + projectRootPath.toAbsolutePath().toString());\n        }\n        return projectRootPath;\n    }\n\n    public static Path createOutputDirectory(String targetDirectory) {\n        Path origin = new File(System.getProperty(\"user.dir\")).toPath();\n        Path outputPath = (targetDirectory == null ? origin : origin.resolve(targetDirectory));\n        try {\n            Files.createDirectories(outputPath);\n        } catch (IOException e) {\n            throw new IllegalArgumentException(\"Could not create directory \" + targetDirectory, e);\n        }\n        return outputPath;\n    }\n\n    public static Set<String> sanitizeExtensions(Set<String> extensions) {\n        if (extensions == null) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/CreateProjectHelper.java#L132-L168","documentation":"checkProjectRootPath computes outputPath/name and refuses to proceed if that directory already exists, to avoid overwriting an existing project. It throws an IllegalArgumentException containing the absolute target directory path.","triggerScenarios":"Calling CreateProject (or checkProjectRootPath directly) where outputPath.resolve(name) already exists on disk — e.g. re-running generation into the same output directory with the same project name.","commonSituations":"Re-running a failed/interrupted generation after some files were created; scaffolding into a directory that already holds another project; running the same script twice without cleaning output.","solutions":["Choose a different project name or output directory","Delete or move the existing target directory before re-running","Point outputPath at an empty location","If overwrite is truly intended, remove the directory explicitly: rm -rf <dir>"],"exampleFix":"// before\ncreateProject.outputDirectory(Path.of(\".\")); createProject.name(\"my-app\"); // ./my-app exists\n// after\nrm -rf ./my-app  // or use name(\"my-app-v2\")","handlingStrategy":"validation","validationCode":"Path root = outputPath.resolve(name);\nif (root.toFile().exists()) { throw new IllegalArgumentException(\"choose another name/output or remove \" + root.toAbsolutePath()); }","typeGuard":null,"tryCatchPattern":"try { helper.checkProjectRootPath(outputPath, name); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Target directory already exists\")) { useAlternateDirOrAbort(); } }","preventionTips":["Check target directory existence before invoking project creation","Use unique output directories per generation run in CI","Clean up failed generation outputs before re-running"],"tags":["filesystem","project-generation","cli"],"backgroundTag":"directory-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"}