{"record":{"id":"fcf2ba59b25ec5b4","repo":"floci-io/floci","slug":"badrequestexception-fcf2ba","errorCode":"BadRequestException","errorMessage":"BrokerName is required","messagePattern":"BrokerName is required","errorType":"http","errorClass":"AwsException","httpStatus":400,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java","lineNumber":72,"sourceCode":"    }\n\n    @PostConstruct\n    public void init() {\n        startReadinessPoller();\n    }\n\n    @PreDestroy\n    public void shutdown() {\n        // Container teardown is wired into EmulatorLifecycle.onStop() via\n        // RabbitMqManager.stopAll() (ordered with the other container managers);\n        // here we only stop the readiness poller.\n        poller.shutdown();\n    }\n\n    public Broker createBroker(CreateBrokerParams params) {\n        String name = params.brokerName();\n        if (name == null || name.isBlank()) {\n            throw new AwsException(\"BadRequestException\", \"BrokerName is required\", 400);\n        }\n        if (!ENGINE_RABBITMQ.equals(params.engineType())) {\n            throw new AwsException(\"BadRequestException\",\n                    \"Only RABBITMQ EngineType is supported\", 400);\n        }\n        String deploymentMode = params.deploymentMode() == null\n                ? DEPLOYMENT_SINGLE_INSTANCE : params.deploymentMode();\n        if (!DEPLOYMENT_SINGLE_INSTANCE.equals(deploymentMode)) {\n            throw new AwsException(\"BadRequestException\",\n                    \"Only SINGLE_INSTANCE DeploymentMode is supported\", 400);\n        }\n        // RabbitMQ brokers require exactly one user at creation; that user becomes the\n        // broker's RabbitMQ administrator (seeded into the container). This mirrors AWS,\n        // which rejects CreateBroker for RabbitMQ unless exactly one user is supplied.\n        List<MqUser> requestedUsers = params.users() == null ? List.of() : params.users();\n        if (requestedUsers.size() != 1) {\n            throw new AwsException(\"BadRequestException\",\n                    \"Exactly one broker user is required for a RabbitMQ broker\", 400);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/amazonmq/AmazonMqService.java#L54-L90","documentation":"AmazonMQ BadRequestException (HTTP 400) thrown by AmazonMqService.createBroker when BrokerName is null or blank. It is the first validation in broker creation, checked before engine type, deployment mode, and users — so a missing name masks later validation errors.","triggerScenarios":"mq.createBroker with a request whose brokerName is null or whitespace — unset builder field, empty string after templating, or a blank value from config. Fails before the RABBITMQ-only engine check runs.","commonSituations":"IaC variables for broker name not wired (Terraform var unset → empty); CLI scripts passing $BROKER_NAME unset; request builders shared across services where the name setter was skipped on one path.","solutions":["Set brokerName explicitly and assert it is non-blank before calling createBroker","Check the variable/parameter feeding the name for typos or unset environment values","Remember downstream constraints: this emulator only accepts EngineType=RABBITMQ and DeploymentMode=SINGLE_INSTANCE, so set those too and avoid the next two errors"],"exampleFix":"// before\nmq.createBroker(r -> r.engineType(\"RABBITMQ\")); // brokerName never set\n\n// after\nString name = Objects.requireNonNull(System.getenv(\"BROKER_NAME\"), \"demo-broker\");\nmq.createBroker(r -> r.brokerName(name).engineType(\"RABBITMQ\").deploymentMode(\"SINGLE_INSTANCE\")\n    .users(adminUser));","handlingStrategy":"validation","validationCode":"if (brokerName == null || brokerName.isBlank()) {\n    throw new IllegalArgumentException(\"BrokerName is required\");\n}","typeGuard":"private static boolean isCreatableBrokerRequest(String name, String engine, String mode) {\n    return name != null && !name.isBlank()\n        && \"RABBITMQ\".equals(engine)\n        && (mode == null || \"SINGLE_INSTANCE\".equals(mode));\n}","tryCatchPattern":"try {\n    mq.createBroker(r -> r.brokerName(name).engineType(\"RABBITMQ\").deploymentMode(\"SINGLE_INSTANCE\").users(u));\n} catch (BadRequestException e) {\n    // inspect message: name/engine/mode each have a distinct validation error\n}","preventionTips":["Make brokerName a required field in your own wrapper around createBroker","Set EngineType=RABBITMQ and DeploymentMode=SINGLE_INSTANCE up front — other values fail the next checks"],"tags":["amazonmq","create-broker","validation","rabbitmq","aws"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}