floci-io/floci · error · AwsException

ConflictException

ConflictException

Error message

Channel namespace already exists: " + name

What it means

Thrown by createChannelNamespace when a namespace with the same name already exists under the API (key apiKey(apiId, name) present in channelNamespaceStore). Unlike most create duplicates here, this is a ConflictException with HTTP 409, reflecting the newer Event API semantics.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java:784

    public void disassociateApi(String domainName) {
        getDomainName(domainName);
        associationStore.get(domainName).ifPresent(apiId -> assertSchemaNotBusy(apiId));
        associationStore.delete(domainName);
    }

    // ──────────────────────────── Channel Namespaces ────────────────────────────

    public ChannelNamespace createChannelNamespace(String apiId, Map<String, Object> request) {
        assertSchemaNotBusy(apiId);
        getGraphqlApi(apiId);
        String name = (String) request.get("name");
        if (name == null || name.isBlank()) {
            throw new AwsException("BadRequestException", "A channel namespace name is required", 400);
        }
        String nsKey = apiKey(apiId, name);
        if (channelNamespaceStore.get(nsKey).isPresent()) {
            throw new AwsException("ConflictException",
                "Channel namespace already exists: " + name, 409);
        }
        ChannelNamespace ns = new ChannelNamespace();
        ns.setName(name);
        ns.setApiId(apiId);
        ns.setDescription((String) request.get("description"));
        ns.setChannelNamespaceArn(regionResolver.buildArn("appsync", regionResolver.getDefaultRegion(),
            "apis/" + apiId + "/channelNamespaces/" + name));
        ns.setCodeHandlers((String) request.get("codeHandlers"));
        ns.setCreated(System.currentTimeMillis());
        ns.setLastModified(System.currentTimeMillis());
        channelNamespaceStore.put(nsKey, ns);
        return ns;
    }

    public ChannelNamespace getChannelNamespace(String apiId, String name) {
        return channelNamespaceStore.get(apiKey(apiId, name))
                .orElseThrow(() -> new AwsException("NotFoundException",

View on GitHub (pinned to 62ff490619)

Solutions

  1. Use the update path (updateChannelNamespace) if the namespace already exists
  2. Delete the namespace before re-creating it
  3. List namespaces first (listChannelNamespaces) and skip existing ones

Example fix

// before
appSync.createChannelNamespace(apiId, Map.of("name", "default")); // 2nd run -> 409

// after
boolean exists = appSync.listChannelNamespaces(apiId, null, null).getItems().stream()
        .anyMatch(ns -> ns.getName().equals("default"));
if (!exists) {
    appSync.createChannelNamespace(apiId, Map.of("name", "default"));
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean exists = appSync.listChannelNamespaces(apiId, null, null).getItems().stream()
        .anyMatch(ns -> ns.getName().equals(name));
if (!exists) appSync.createChannelNamespace(apiId, request);

Try / catch

try {
    appSync.createChannelNamespace(apiId, request);
} catch (AwsException e) {
    if ("ConflictException".equals(e.getCode()) && e.getMessage().contains("already exists")) {
        appSync.updateChannelNamespace(apiId, name, request); // upsert
    } else throw e;
}

Prevention

When it happens

Trigger: Calling createChannelNamespace twice with the same name on the same apiId; provisioning scripts that create the 'default' namespace on every run.

Common situations: Idempotent deployment tooling; retrying after a network error where the first create actually succeeded; shared emulator state across tests.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/fdb5994a8103800a. Report an issue: GitHub.