{"record":{"id":"5fa4a4a34b81b1c7","repo":"floci-io/floci","slug":"invalidrequestexception-5fa4a4","errorCode":"InvalidRequestException","errorMessage":"primary workGroup could not be created","messagePattern":"primary workGroup could not be created","errorType":"error_code","errorClass":"AwsException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java","lineNumber":134,"sourceCode":"                .orElseThrow(() -> new AwsException(\"InvalidRequestException\",\n                        \"Query execution not found: \" + id, 400));\n    }\n\n    public List<QueryExecution> listQueryExecutions() {\n        return queryStore.scan(k -> true);\n    }\n\n    public void stopQueryExecution(String id) {\n        QueryExecution execution = getQueryExecution(id);\n        execution.getStatus().setState(QueryExecutionState.CANCELLED);\n        execution.getStatus().setCompletionDateTime(Instant.now());\n        queryStore.put(id, execution);\n    }\n\n    public WorkGroup createWorkGroup(CreateWorkGroupRequest request, String region) {\n        validateWorkGroupName(request.getName());\n        if (DEFAULT_WORKGROUP.equals(request.getName())) {\n            throw new AwsException(\"InvalidRequestException\",\n                    DEFAULT_WORKGROUP + \" workGroup could not be created\", 400);\n        }\n        String key = workGroupKey(region, request.getName());\n        if (workGroupStore.get(key).isPresent()) {\n            throw new AwsException(\"InvalidRequestException\", \"WorkGroup already exists\", 400);\n        }\n\n        WorkGroup workGroup = new WorkGroup();\n        workGroup.setName(request.getName());\n        workGroup.setDescription(request.getDescription());\n        workGroup.setState(\"ENABLED\");\n        workGroup.setCreationTime(Instant.now());\n        workGroup.setTags(normalizeTags(request.getTags()));\n        workGroup.setConfiguration(normalizeWorkGroupConfiguration(request.getConfiguration()));\n        workGroupStore.put(key, workGroup);\n        return workGroup;\n    }\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java#L116-L152","documentation":"Raised by the Athena emulator's CreateWorkGroup when the requested name equals 'primary'. AWS Athena pre-creates the 'primary' workgroup in every account/region, so attempting to create it again fails with InvalidRequestException / HTTP 400.","triggerScenarios":"athenaClient.createWorkGroup(r -> r.name(\"primary\")) or aws athena create-work-group --name primary. Happens in setup scripts that hardcode 'primary' as the default workgroup name.","commonSituations":"Applications defaulting to the primary workgroup and calling create unconditionally on startup; idempotent provisioning code that tries create-then-ignore-error instead of checking existence first.","solutions":["Use the existing primary workgroup directly — no create call needed for it.","If provisioning custom workgroups, pick a non-reserved name and check getWorkGroup() existence before createWorkGroup().","Make bootstrap idempotent: catch/tolerate AlreadyExists-style outcomes instead of always creating."],"exampleFix":"// before\nathenaClient.createWorkGroup(r -> r.name(\"primary\").configuration(c -> c.resultConfiguration(...)));\n\n// after\ntry {\n    athenaClient.getWorkGroup(r -> r.workGroup(\"primary\"));\n} catch (Exception e) {\n    athenaClient.createWorkGroup(r -> r.name(\"my-wg\").configuration(c -> c.resultConfiguration(...)));\n}","handlingStrategy":"validation","validationCode":"static void requireCreatableWorkGroup(String name) {\n    if (\"primary\".equals(name))\n        throw new IllegalArgumentException(\"'primary' already exists; use it instead of creating it\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    athenaClient.createWorkGroup(req);\n} catch (InvalidRequestException e) {\n    if (e.getMessage().contains(\"could not be created\") && \"primary\".equals(req.name())) {\n        return; // idempotent no-op: primary always exists\n    }\n    throw e;\n}","preventionTips":["Default query execution to the existing primary workgroup instead of creating one.","Make provisioning code check getWorkGroup() before createWorkGroup().","Unit-test bootstrap against the reserved-name rule."],"tags":["athena","workgroup","reserved-name","create","aws-emulator"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}