Skip to content

Commit db428f1

Browse files
authored
fix: validate projection engineVersion and V2 trackEmittedStreams combo (#390)
* fix: validate projection engineVersion and V2 trackEmittedStreams combo Reject engineVersion values outside the documented set (0/1/2) and the V2 + trackEmittedStreams combination before sending the request. * fix: deliver projection validation error via exceptional completion Match how server-side failures of the same condition surface; keep the public CompletableFuture API free of synchronous throws. * style: rename failed future variable to result for consistency
1 parent 5428640 commit db428f1

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/main/java/io/kurrent/dbclient/CreateProjection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public CreateProjection(final GrpcClient client, final String projectionName, fi
2929

3030
@SuppressWarnings("unchecked")
3131
public CompletableFuture execute() {
32+
if (engineVersion == 2 && trackEmittedStreams) {
33+
CompletableFuture<Projectionmanagement.CreateResp> result = new CompletableFuture<>();
34+
result.completeExceptionally(new IllegalArgumentException(
35+
"trackEmittedStreams is not supported when engineVersion is 2 (V2)"));
36+
return result;
37+
}
38+
3239
return this.client.run(channel -> {
3340
Projectionmanagement.CreateReq.Options.Continuous.Builder continuousBuilder =
3441
Projectionmanagement.CreateReq.Options.Continuous.newBuilder()

src/main/java/io/kurrent/dbclient/CreateProjectionOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ public CreateProjectionOptions emitEnabled(boolean value) {
5454
* The engine version is pinned at create time and cannot be changed via update.
5555
* V2 has limitations versus V1: {@code trackEmittedStreams} is rejected,
5656
* result streams are not emitted, and bi-state projections are not supported.
57+
*
58+
* @throws IllegalArgumentException if {@code value} is not {@code 0}, {@code 1}, or {@code 2}.
5759
*/
5860
public CreateProjectionOptions engineVersion(int value) {
61+
if (value < 0 || value > 2) {
62+
throw new IllegalArgumentException(
63+
"engineVersion must be 0, 1, or 2 (got " + value + ")");
64+
}
5965
this.engineVersion = value;
6066
return this;
6167
}

0 commit comments

Comments
 (0)