Skip to content

Commit 19d60f5

Browse files
committed
change IllegalStateException to IllegalArgumentException
1 parent ac8289a commit 19d60f5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

modules/ingest-common/src/yamlRestTest/resources/rest-api-spec/test/ingest/290_versioned_update.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
# required version does not match specified version
4949
- do:
50-
catch: /.*version conflict, required version \[99\] for pipeline \[my_pipeline\] but current version is \[1\].*/
50+
catch: bad_request
5151
ingest.put_pipeline:
5252
id: "my_pipeline"
5353
if_version: 99
@@ -66,7 +66,7 @@
6666
6767
# may not update to same version
6868
- do:
69-
catch: /.*cannot update pipeline \[my_pipeline\] with the same version \[1\].*/
69+
catch: bad_request
7070
ingest.put_pipeline:
7171
id: "my_pipeline"
7272
if_version: 1
@@ -86,7 +86,7 @@
8686
8787
# cannot conditionally update non-existent pipeline
8888
- do:
89-
catch: /.*version conflict, required version \[1\] for pipeline \[my_pipeline2\] but no pipeline was found.*/
89+
catch: bad_request
9090
ingest.put_pipeline:
9191
id: "my_pipeline2"
9292
if_version: 1

server/src/main/java/org/elasticsearch/ingest/IngestService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static ClusterState innerPut(PutPipelineRequest request, ClusterState currentSta
446446
if (request.isVersionedUpdate()) {
447447
var currentPipeline = currentIngestMetadata != null ? currentIngestMetadata.getPipelines().get(request.getId()) : null;
448448
if (currentPipeline == null) {
449-
throw new IllegalStateException(String.format(
449+
throw new IllegalArgumentException(String.format(
450450
Locale.ROOT,
451451
"version conflict, required version [%s] for pipeline [%s] but no pipeline was found",
452452
request.getVersion(),
@@ -456,7 +456,7 @@ static ClusterState innerPut(PutPipelineRequest request, ClusterState currentSta
456456

457457
final Integer currentVersion = currentPipeline.getVersion();
458458
if (Objects.equals(request.getVersion(), currentVersion) == false) {
459-
throw new IllegalStateException(String.format(
459+
throw new IllegalArgumentException(String.format(
460460
Locale.ROOT,
461461
"version conflict, required version [%s] for pipeline [%s] but current version is [%s]",
462462
request.getVersion(),
@@ -468,7 +468,7 @@ static ClusterState innerPut(PutPipelineRequest request, ClusterState currentSta
468468
var pipelineConfig = XContentHelper.convertToMap(request.getSource(), false, request.getXContentType()).v2();
469469
final Integer specifiedVersion = (Integer) pipelineConfig.get("version");
470470
if (pipelineConfig.containsKey("version") && Objects.equals(specifiedVersion, currentVersion)) {
471-
throw new IllegalStateException(String.format(
471+
throw new IllegalArgumentException(String.format(
472472
Locale.ROOT,
473473
"cannot update pipeline [%s] with the same version [%s]",
474474
request.getId(),

server/src/test/java/org/elasticsearch/ingest/IngestServiceTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ public void testPutPipelineWithVersionedUpdateWithoutExistingPipeline() throws E
15571557
var request = new PutPipelineRequest(pipelineId, new BytesArray(pipelineString), XContentType.JSON);
15581558
request.setVersionedUpdate(true);
15591559
request.setVersion(version);
1560-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> IngestService.innerPut(request, clusterState));
1560+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> IngestService.innerPut(request, clusterState));
15611561
assertThat(
15621562
e.getMessage(),
15631563
equalTo(String.format(
@@ -1585,7 +1585,7 @@ public void testPutPipelineWithVersionedUpdateDoesNotMatchExistingPipeline() {
15851585
var request = new PutPipelineRequest(pipelineId, new BytesArray(pipelineString), XContentType.JSON);
15861586
request.setVersionedUpdate(true);
15871587
request.setVersion(requestedVersion);
1588-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> IngestService.innerPut(request, clusterState));
1588+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> IngestService.innerPut(request, clusterState));
15891589
assertThat(
15901590
e.getMessage(),
15911591
equalTo(String.format(
@@ -1613,7 +1613,7 @@ public void testPutPipelineWithVersionedUpdateSpecifiesSameVersion() throws Exce
16131613
var request = new PutPipelineRequest(pipelineId, new BytesArray(pipelineString), XContentType.JSON);
16141614
request.setVersionedUpdate(true);
16151615
request.setVersion(version);
1616-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> IngestService.innerPut(request, clusterState));
1616+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> IngestService.innerPut(request, clusterState));
16171617
assertThat(
16181618
e.getMessage(),
16191619
equalTo(String.format(

0 commit comments

Comments
 (0)