{"record":{"id":"7c11aef6b2c58fae","repo":"floci-io/floci","slug":"resourcealreadyexistsexception","errorCode":"ResourceAlreadyExistsException","errorMessage":"Project already exists:  \" + name","messagePattern":"Project already exists:  \" \\+ name","errorType":"exception","errorClass":"AwsException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java","lineNumber":134,"sourceCode":"\n    // ---- Projects ----\n\n    public Project createProject(String region, String account,\n                                 String name, String description,\n                                 ProjectSource source, List<ProjectSource> secondarySources,\n                                 String sourceVersion,\n                                 ProjectArtifacts artifacts, List<ProjectArtifacts> secondaryArtifacts,\n                                 ProjectEnvironment environment,\n                                 String serviceRole,\n                                 Integer timeoutInMinutes, Integer queuedTimeoutInMinutes,\n                                 String encryptionKey,\n                                 List<Map<String, String>> tags,\n                                 Map<String, Object> logsConfig,\n                                 Map<String, Object> vpcConfig,\n                                 Integer concurrentBuildLimit) {\n        Map<String, Project> store = projectsFor(region);\n        if (store.containsKey(name)) {\n            throw new AwsException(\"ResourceAlreadyExistsException\",\n                    \"Project already exists: \" + name, 400);\n        }\n        validateProjectName(name);\n        if (source == null || source.getType() == null) {\n            throw new AwsException(\"InvalidInputException\", \"source.type is required\", 400);\n        }\n        if (environment == null) {\n            throw new AwsException(\"InvalidInputException\", \"environment is required\", 400);\n        }\n        if (serviceRole == null || serviceRole.isBlank()) {\n            throw new AwsException(\"InvalidInputException\", \"serviceRole is required\", 400);\n        }\n        if (artifacts == null || artifacts.getType() == null) {\n            throw new AwsException(\"InvalidInputException\", \"artifacts.type is required\", 400);\n        }\n\n        double now = Instant.now().toEpochMilli() / 1000.0;\n        Project project = new Project();","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/codebuild/CodeBuildService.java#L116-L152","documentation":"Thrown by CodeBuildService.createProject when a project with the same name already exists in the region's project store. Checked before any validation of the payload. Maps to AWS ResourceAlreadyExistsException, though Floci returns it with HTTP 400.","triggerScenarios":"Running CreateProject twice with the same name; re-running an infrastructure bootstrap script (CDK/Terraform apply) that calls CreateProject instead of UpdateProject on subsequent runs; IaC templates that hardcode a shared project name across environments in the same Floci region.","commonSituations":"Idempotent deployment scripts that assume create-or-update semantics; concurrent CI jobs creating the same named project; test suites that do not clean up projects between runs.","solutions":["Delete the existing project first (DeleteProject) if you intend to recreate it","Use UpdateProject for subsequent applies of changed configuration","Make bootstrap scripts idempotent: check BatchGetProjects/list-projects before CreateProject","Use unique names per environment/job to avoid collisions"],"exampleFix":"# before\naws --endpoint-url http://localhost:4566 codebuild create-project --name demo ...\n# -> ResourceAlreadyExistsException on re-run\n\n# after\nname=demo-$(date +%s)  # or:\naws --endpoint-url http://localhost:4566 codebuild delete-project --name demo || true\naws --endpoint-url http://localhost:4566 codebuild create-project --name demo ...","handlingStrategy":"validation","validationCode":"// Java, SDK v2 - existence check before create\nboolean exists = codebuild.batchGetProjects(r -> r.names(name)).projects().stream()\n        .anyMatch(p -> p.name().equals(name));\nif (exists) throw new IllegalStateException(\"Project \" + name + \" already exists - update instead\");","typeGuard":null,"tryCatchPattern":"catch (ResourceAlreadyExistsException e) {\n    // decide policy: adopt existing project (update) or delete+recreate; never blind-retry create\n    if (adoptExisting) codebuild.updateProject(toUpdate(name, cfg));\n    else { codebuild.deleteProject(r -> r.name(name)); codebuild.createProject(cfg); }\n}","preventionTips":["Make bootstrap scripts create-or-update idempotent","Use unique project names per environment/CI job","Clean up test projects in teardown"],"tags":["codebuild","create-project","duplicate","conflict"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}