quarkusio/quarkus · error · IllegalArgumentException

Cannot combine `WITHLABELS` and `SELECTED_LABELS`

Error message

Cannot combine `WITHLABELS` and `SELECTED_LABELS`

What it means

MRangeArgs.toArgs() serializes TS_MRANGE options. RedisTimeSeries does not allow WITHLABELS together with SELECTED_LABELS, so the builder throws when both were set on the same instance. Like error 1732 but on MRangeArgs; the failure surfaces when the command is built, not when the setters ran.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MRangeArgs.java:232

            list.add("FILTER_BY_TS");
            for (Long ts : filterByTimestamps) {
                list.add(Long.toString(ts));
            }
        }

        if (filterByValue) {
            list.add("FILTER_BY_VALUE");
            list.add(Double.toString(min)); // TODO Check format
            list.add(Double.toString(max));
        }

        if (withLabels) {
            list.add("WITHLABELS");
        }

        if (selectedLabels != null && selectedLabels.length != 0) {
            if (withLabels) {
                throw new IllegalArgumentException("Cannot combine `WITHLABELS` and `SELECTED_LABELS`");
            }

            list.add("SELECTED_LABELS");
            list.addAll(Arrays.asList(selectedLabels));
        }

        if (count != -1) {
            list.add("COUNT");
            list.add(Integer.toString(count));
        }

        if (aggregation != null) {
            if (align != null) {
                list.add("ALIGN");
                list.add(align);
            }

            list.add("AGGREGATION");

View on GitHub (pinned to e1c734241f)

Solutions

  1. Drop selectedLabels(...) to request all labels via WITHLABELS
  2. Drop withLabels() and keep only the SELECTED_LABELS list
  3. Refactor the builder flow into exclusive branches so both flags can never be set together

Example fix

// before
MRangeArgs args = MRangeArgs.Builder.getInstance()
    .withLabels()
    .selectedLabels("region", "rack");
// after
MRangeArgs args = MRangeArgs.Builder.getInstance()
    .selectedLabels("region", "rack");
Defensive patterns

Strategy: validation

Validate before calling

if (withLabels && selectedLabels != null && selectedLabels.length > 0) {
    throw new IllegalArgumentException("WITHLABELS and SELECTED_LABELS are mutually exclusive");
}

Type guard

boolean argsValid(boolean withLabels, String... selectedLabels) {
    return !(withLabels && selectedLabels != null && selectedLabels.length > 0);
}

Try / catch

try {
    redis.ts().mrange(args);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("SELECTED_LABELS")) {
        args = MRangeArgs.Builder.getInstance().selectedLabels(labels);
    }
}

Prevention

When it happens

Trigger: Calling mrangeArgs.withLabels() (withLabels flag set) and also .selectedLabels("x","y") on the same instance before toArgs() executes.

Common situations: Merging argument-building code paths that each set one option; reusing a cached args object; documentation examples mixing the two options.

Related errors


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