Skip to content

Commit 4baa39a

Browse files
consolidate error messages and exceptions thrown
1 parent ae8cc1a commit 4baa39a

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ private static <V> V splitSelectorExpression(String expression, BiFunction<Strin
23682368
IndexComponentSelector selector = resolveAndValidateSelectorString(() -> expression, suffix);
23692369
String expressionBase = expression.substring(0, lastDoubleColon);
23702370
ensureNoMoreSelectorSeparators(expressionBase, expression);
2371-
ensureNoCrossClusterExpressionWithSelectorSeparator(expressionBase, selector, expression);
2371+
ensureNotMixingRemoteClusterExpressionWithSelectorSeparator(expressionBase, selector, expression);
23722372
return bindFunction.apply(expressionBase, suffix);
23732373
}
23742374
// Otherwise accept the default
@@ -2420,24 +2420,17 @@ private static void ensureNoMoreSelectorSeparators(String remainingExpression, S
24202420
}
24212421

24222422
/**
2423-
* Checks the expression for cross-cluster syntax and throws an exception if it is combined with ::failures selector.
2424-
* @throws IllegalArgumentException if cross-cluster syntax is detected after parsing the selector expression
2423+
* Checks the expression for remote cluster pattern and throws an exception if it is combined with :: selectors.
2424+
* @throws InvalidIndexNameException if remote cluster pattern is detected after parsing the selector expression
24252425
*/
2426-
private static void ensureNoCrossClusterExpressionWithSelectorSeparator(
2426+
private static void ensureNotMixingRemoteClusterExpressionWithSelectorSeparator(
24272427
String expressionWithoutSelector,
24282428
IndexComponentSelector selector,
24292429
String originalExpression
24302430
) {
24312431
if (selector != null) {
24322432
if (RemoteClusterAware.isRemoteIndexName(expressionWithoutSelector)) {
2433-
throw new IllegalArgumentException(
2434-
"Invalid usage of ["
2435-
+ SELECTOR_SEPARATOR
2436-
+ selector.getKey()
2437-
+ "] selector in ["
2438-
+ originalExpression
2439-
+ "], selectors are not supported with cross-cluster expressions"
2440-
);
2433+
throw new InvalidIndexNameException(originalExpression, "Selectors are not yet supported on remote cluster patterns");
24412434
}
24422435
}
24432436
}

server/src/test/java/org/elasticsearch/cluster/metadata/SelectorResolverTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public void testResolveExpression() {
115115
"*:-test*,*::data"
116116
);
117117
for (String expression : remoteClusterExpressionsWithSelectors) {
118-
var e = expectThrows(IllegalArgumentException.class, () -> resolve(selectorsAllowed, expression));
119-
assertThat(e.getMessage(), containsString("selectors are not supported with cross-cluster expressions"));
118+
var e = expectThrows(InvalidIndexNameException.class, () -> resolve(selectorsAllowed, expression));
119+
assertThat(e.getMessage(), containsString("Selectors are not yet supported on remote cluster patterns"));
120120
}
121121
}
122122

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,13 @@ public void testInvalidCharacterInIndexPattern() {
636636
expectDoubleColonErrorWithLineNumber(command, "*:*::failures", parseLineNumber + 3);
637637

638638
// Too many colons
639-
expectInvalidIndexNameErrorWithLineNumber(command, "\"index:::data\"", lineNumber, "index:", "must not contain ':'");
639+
expectInvalidIndexNameErrorWithLineNumber(
640+
command,
641+
"\"index:::data\"",
642+
lineNumber,
643+
"index:::data",
644+
"Selectors are not yet supported on remote cluster patterns"
645+
);
640646
expectInvalidIndexNameErrorWithLineNumber(
641647
command,
642648
"\"index::::data\"",

x-pack/plugin/security/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/remotecluster/AbstractRemoteClusterSecurityFailureStoreRestIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected Tuple<String, String> getSingleDataAndFailureIndices(String dataStream
171171

172172
protected static void assertSelectorsNotSupported(ResponseException exception) {
173173
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(403));
174-
assertThat(exception.getMessage(), containsString("selectors are not supported with cross-cluster expressions"));
174+
assertThat(exception.getMessage(), containsString("Selectors are not yet supported on remote cluster patterns"));
175175
}
176176

177177
}

0 commit comments

Comments
 (0)