floci-io/floci · error · AwsException

InconsistentQuantities

InconsistentQuantities

Error message

The value of Quantity does not match the number of items.

What it means

Floci's CloudFront emulator cross-checks the declared Quantity against the actual number of KeyGroupId items in a TrustedKeyGroups block. If they differ it throws InconsistentQuantities (HTTP 400), the AWS error used for count/item mismatches in list-encoded XML.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontController.java:2785

            return quantity;
        } catch (NumberFormatException e) {
            throw new AwsException(
                    "InvalidArgument",
                    "TrustedKeyGroups Quantity must be a non-negative integer.",
                    400);
        }
    }

    private static void validateTrustedKeyGroupsQuantity(
            Integer quantity, int itemCount) {
        if (quantity == null) {
            throw new AwsException(
                    "InvalidArgument",
                    "TrustedKeyGroups must include Quantity.",
                    400);
        }
        if (quantity != itemCount) {
            throw new AwsException(
                    "InconsistentQuantities",
                    "The value of Quantity does not match the number of items.",
                    400);
        }
    }

    private static void validateEnabledTrustedKeyGroups(
            boolean enabled, int itemCount) {
        if (enabled && itemCount == 0) {
            throw new AwsException(
                    "InvalidArgument",
                    "TrustedKeyGroups cannot be enabled without a key group.",
                    400);
        }
    }

    private List<String> parseAliases(String body) {
        List<String> result = new ArrayList<>();

View on GitHub (pinned to 62ff490619)

Solutions

  1. Set Quantity to exactly the number of KeyGroupId elements in Items
  2. Derive Quantity programmatically from the list size instead of hardcoding
  3. After editing a config fetched from GET, recount items before resubmitting

Example fix

<!-- before: says 3, lists 2 -->
<Quantity>3</Quantity>
<Items><KeyGroupId>kg-1</KeyGroupId><KeyGroupId>kg-2</KeyGroupId></Items>

<!-- after -->
<Quantity>2</Quantity>
<Items><KeyGroupId>kg-1</KeyGroupId><KeyGroupId>kg-2</KeyGroupId></Items>
Defensive patterns

Strategy: validation

Validate before calling

static void checkQuantityMatches(Integer declared, List<String> items) {
    if (declared == null || declared != items.size()) {
        throw new IllegalArgumentException(
            "Quantity " + declared + " != item count " + items.size());
    }
}

Try / catch

try {
    cf.updateDistribution(req -> req.id(id).ifMatch(etag).distributionConfig(cfg));
} catch (CloudFrontException e) {
    if ("InconsistentQuantities".equals(e.awsErrorDetails().errorCode())) {
        // set Quantity = items.size() and retry once
    } else { throw e; }
}

Prevention

When it happens

Trigger: Sending <Quantity>3</Quantity> with only 2 KeyGroupId items (or vice versa) in DefaultCacheBehavior or any CacheBehavior's TrustedKeyGroups.

Common situations: Hardcoded Quantity that goes stale when items are added/removed; hand-merged configs where the list changed but the count was not updated.

Related errors


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