Skip to content

Commit 3ab8f53

Browse files
committed
Improved custom message ctor and fixed its usages.
1 parent edf6301 commit 3ab8f53

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

server/src/main/java/org/elasticsearch/action/support/AutoCreateIndex.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public boolean shouldAutoCreate(String index, ClusterState state) {
7373
// One volatile read, so that all checks are done against the same instance:
7474
final AutoCreate autoCreate = this.autoCreate;
7575
if (autoCreate.autoCreateIndex == false) {
76-
throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] is [false]", index);
76+
throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] is [false]", index);
7777
}
7878
if (dynamicMappingDisabled) {
79-
throw new IndexNotFoundException("no such index and [" + MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey() + "] is [false]",
79+
throw new IndexNotFoundException("[" + MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey() + "] is [false]",
8080
index);
8181
}
8282
// matches not set, default value of "true"
@@ -90,11 +90,11 @@ public boolean shouldAutoCreate(String index, ClusterState state) {
9090
if (include) {
9191
return true;
9292
}
93-
throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-"
93+
throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] contains [-"
9494
+ indexExpression + "] which forbids automatic creation of the index", index);
9595
}
9696
}
97-
throw new IndexNotFoundException("no such index and [" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate
97+
throw new IndexNotFoundException("[" + AUTO_CREATE_INDEX_SETTING.getKey() + "] ([" + autoCreate
9898
+ "]) doesn't match", index);
9999
}
100100

server/src/main/java/org/elasticsearch/index/IndexNotFoundException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class IndexNotFoundException extends ResourceNotFoundException {
2828
* Construct with a custom message.
2929
*/
3030
public IndexNotFoundException(String message, String index) {
31-
super(message);
31+
super("no such index [" + index + "] and " + message);
3232
setIndex(index);
3333
}
3434

server/src/test/java/org/elasticsearch/action/support/AutoCreateIndexTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ public void testHandleSpaces() { // see #21449
8383
public void testAutoCreationDisabled() {
8484
Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false).build();
8585
AutoCreateIndex autoCreateIndex = newAutoCreateIndex(settings);
86+
String randomIndex = randomAlphaOfLengthBetween(1, 10);
8687
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () ->
87-
autoCreateIndex.shouldAutoCreate(randomAlphaOfLengthBetween(1, 10), buildClusterState()));
88-
assertEquals("no such index and [action.auto_create_index] is [false]", e.getMessage());
88+
autoCreateIndex.shouldAutoCreate(randomIndex, buildClusterState()));
89+
assertEquals("no such index [" + randomIndex + "] and [action.auto_create_index] is [false]", e.getMessage());
8990
}
9091

9192
public void testAutoCreationEnabled() {
@@ -207,14 +208,15 @@ private AutoCreateIndex newAutoCreateIndex(Settings settings) {
207208
private void expectNotMatch(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index) {
208209
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () ->
209210
autoCreateIndex.shouldAutoCreate(index, clusterState));
210-
assertEquals("no such index and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match",
211-
e.getMessage());
211+
assertEquals(
212+
"no such index [" + index + "] and [action.auto_create_index] ([" + autoCreateIndex.getAutoCreate() + "]) doesn't match",
213+
e.getMessage());
212214
}
213215

214216
private void expectForbidden(ClusterState clusterState, AutoCreateIndex autoCreateIndex, String index, String forbiddingPattern) {
215217
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () ->
216218
autoCreateIndex.shouldAutoCreate(index, clusterState));
217-
assertEquals("no such index and [action.auto_create_index] contains [" + forbiddingPattern
219+
assertEquals("no such index [" + index + "] and [action.auto_create_index] contains [" + forbiddingPattern
218220
+ "] which forbids automatic creation of the index", e.getMessage());
219221
}
220222
}

0 commit comments

Comments
 (0)