quarkusio/quarkus · error · IllegalArgumentException

ANY can only be used if COUNT is also set

Error message

ANY can only be used if COUNT is also set

What it means

In GeoSearchStoreArgs.toArgs(), the ANY option is only valid in Redis when paired with COUNT. If any=true was set but no count was provided (count == -1), the library throws IllegalArgumentException to prevent sending an invalid GEOSEARCHSTORE command.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/geo/GeoSearchStoreArgs.java:152

    /**
     * When ANY is provided the command will return as soon as enough matches are found, so the results may not be the
     * ones closest to the specified point, but on the other hand, the effort invested by the server is significantly
     * lower.
     * <p>
     * Using {@code ANY} requires {@code count} to be set.
     *
     * @return the current {@code GeoSearchStoreArgs}
     **/
    public GeoSearchStoreArgs<V> any() {
        this.any = true;
        return this;
    }

    @Override
    public List<Object> toArgs(Codec codec) {
        // Validation
        if (any && count == -1) {
            throw new IllegalArgumentException("ANY can only be used if COUNT is also set");
        }

        if (radius > 0 && width > 0) {
            throw new IllegalArgumentException("BYRADIUS and BYBOX cannot be used together");
        }

        if (member != null && (latitude != Double.MIN_VALUE || longitude != Double.MIN_VALUE)) {
            throw new IllegalArgumentException("FROMMEMBER and FROMLONLAT cannot be used together");
        }

        List<Object> list = new ArrayList<>();
        if (member != null) {
            list.add("FROMMEMBER");
            list.add(new String(codec.encode(member), StandardCharsets.UTF_8));
        } else {
            list.add("FROMLONLAT");
            list.add(Double.toString(longitude));
            list.add(Double.toString(latitude));

View on GitHub (pinned to e1c734241f)

Solutions

  1. Always pair any() with count(n), e.g. args.any().count(10)
  2. Remove the any() call if unbounded results are desired
  3. Add a builder-level invariant or test asserting any implies count

Example fix

// before
args.any(); // missing count
// after
args.any().count(10);
Defensive patterns

Strategy: validation

Validate before calling

if (useAny && count <= 0) {
    throw new IllegalStateException("any() requires a positive count(n)");
}
GeoSearchStoreArgs<V> args = base.anyIf(useAny).count(count);

Try / catch

try {
    geoSearchStore(key, dest, args);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("ANY can only be used if COUNT")) {
        args.count(DEFAULT_COUNT);
        geoSearchStore(key, dest, args);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling any() (or any(true)) on GeoSearchStoreArgs without also calling count(n); conditionally setting any without setting count on that code path.

Common situations: Copy-pasting arg builders between GeoSearchArgs/GeoSearchStoreArgs where count was set elsewhere; a config flag enables ANY but the count option was forgotten; refactor dropped the count call.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/59bdc50af21fcc50. Report an issue: GitHub.