quarkusio/quarkus · error · IllegalArgumentException
Cannot use `WITHLABELS` and `SELECTED_LABELS together
Error message
Cannot use `WITHLABELS` and `SELECTED_LABELS together
What it means
MGetArgs.toArgs() builds the TS.MGET command argument list for RedisTimeSeries. The RedisTimeSeries protocol forbids combining WITHLABELS with SELECTED_LABELS (the latter already returns selected labels), so the builder rejects the mutually exclusive combination when serializing. Note the error occurs at toArgs() time, not when the setters were called.
Source
Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/timeseries/MGetArgs.java:72
selectedLabels.add(nonNull(label, "label"));
return this;
}
@Override
public List<Object> toArgs() {
List<Object> list = new ArrayList<>();
if (latest) {
list.add("LATEST");
}
if (withLabels) {
list.add("WITHLABELS");
}
if (!selectedLabels.isEmpty()) {
list.add("SELECTED_LABELS");
list.addAll(selectedLabels);
}
if (withLabels && !selectedLabels.isEmpty()) {
throw new IllegalArgumentException("Cannot use `WITHLABELS` and `SELECTED_LABELS together");
}
return list;
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Remove the selectedLabels(...) call if you want all labels (WITHLABELS)
- Remove the withLabels(true) call if you only need specific labels via selectedLabels(...)
- If args are built conditionally, make the two options mutually exclusive branches
Example fix
// before
MGetArgs args = MGetArgs.Builder.getInstance()
.withLabels(true)
.selectedLabels("sensor", "location");
// after
MGetArgs args = MGetArgs.Builder.getInstance()
.selectedLabels("sensor", "location"); Defensive patterns
Strategy: validation
Validate before calling
if (withLabels && selectedLabels != null && !selectedLabels.isEmpty()) {
throw new IllegalArgumentException("Use either WITHLABELS or SELECTED_LABELS, not both");
} Type guard
boolean isExclusiveValid(boolean withLabels, java.util.List<String> selected) {
return !withLabels || selected == null || selected.isEmpty();
} Try / catch
try {
redis.ts().mget(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("WITHLABELS")) {
args = rebuildWithoutWithLabels();
}
} Prevention
- Decide the label strategy once (all labels vs selected) before building args
- Build args in a single code path, not merged conditional branches
- Wrap arg construction in a helper that enforces exclusivity
When it happens
Trigger: Calling mgetArgs.withLabels(true) (or the WITHLABELS setter) and also .selectedLabels("a","b") on the same MRangeArgs/MGetArgs instance, then invoking toArgs() when sending the command.
Common situations: Conditional building code where one branch sets WITHLABELS and another adds selected labels; reusing a shared args object across calls; copying example code that sets both options.
Related errors
- Cannot combine `WITHLABELS` and `SELECTED_LABELS`
- The timestamp must be positive
- The timestamp must be positive
- `timeout` must not be `null`
- `timestamp` must not be `null`
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/254f63e3af9d369d.
Report an issue: GitHub.