Skip to content

Commit 6c110ce

Browse files
benwtrentgeorgewallace
authored andcommitted
Adjust exception thrown when unable to load hunspell dict (elastic#123743)
On index creation, its possible to configure an hunspell analyzer, but reference a locale file that actually doesn't exist or isn't accessible. This error, like our other user dictionary errors, should be an IAE not an ISE. closes: elastic#123729
1 parent 8e67c6f commit 6c110ce

File tree

7 files changed

+44
-14
lines changed

7 files changed

+44
-14
lines changed

docs/changelog/123743.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123743
2+
summary: Adjust exception thrown when unable to load hunspell dict
3+
area: Analysis
4+
type: bug
5+
issues: []

modules/analysis-common/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* your election, the "Elastic License 2.0", the "GNU Affero General Public
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
9-
import org.elasticsearch.gradle.Version
10-
119
apply plugin: 'elasticsearch.internal-yaml-rest-test'
1210
apply plugin: 'elasticsearch.yaml-rest-compat-test'
1311
apply plugin: 'elasticsearch.internal-cluster-test'
@@ -36,6 +34,7 @@ artifacts {
3634

3735
tasks.named("yamlRestCompatTestTransform").configure { task ->
3836
task.replaceValueInMatch("tokens.0.token", "absenț", "romanian")
37+
task.skipTest("indices.analyze/15_analyze/Custom analyzer is not buildable", "error response changed with #123743")
3938
}
4039

4140
tasks.named("yamlRestTest").configure {

modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/indices.analyze/15_analyze.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@
6464
"Custom analyzer is not buildable":
6565
- requires:
6666
test_runner_features: [ capabilities ]
67-
reason: This capability required to run test
6867
capabilities:
69-
- method: GET
70-
path: /_analyze
71-
capabilities: [ wrong_custom_analyzer_returns_400 ]
68+
- method: PUT
69+
path: /{index}
70+
capabilities: [ hunspell_dict_400 ]
71+
reason: "bugfix 'hunspell_dict_400' capability required"
7272

7373
- do:
7474
catch: bad_request
@@ -80,7 +80,3 @@
8080
filter:
8181
type: hunspell
8282
locale: en_US
83-
84-
- match: { status: 400 }
85-
- match: { error.type: illegal_argument_exception }
86-
- match: { error.reason: "Can not build a custom analyzer" }

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/10_basic.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,30 @@
273273

274274
- match: { error.type: "mapper_parsing_exception" }
275275
- match: { error.reason: "Failed to parse mapping: The mapper type [invalid] declared on field [raw] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }
276+
---
277+
"Create index with hunspell missing dict":
278+
- requires:
279+
test_runner_features: [ capabilities ]
280+
capabilities:
281+
- method: PUT
282+
path: /{index}
283+
capabilities: [ hunspell_dict_400 ]
284+
reason: "bugfix 'hunspell_dict_400' capability required"
285+
286+
- do:
287+
catch: bad_request
288+
indices.create:
289+
index: bad_hunspell_index
290+
body:
291+
settings:
292+
analysis:
293+
analyzer:
294+
en:
295+
tokenizer: standard
296+
filter:
297+
- my_en_US_dict_stemmer
298+
filter:
299+
my_en_US_dict_stemmer:
300+
type: hunspell
301+
locale: en_US
302+
dedup: false

server/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public HunspellService(final Settings settings, final Environment env, final Map
9999
try {
100100
return loadDictionary(locale, settings, env);
101101
} catch (Exception e) {
102-
throw new IllegalStateException("failed to load hunspell dictionary for locale: " + locale, e);
102+
throw new IllegalArgumentException("failed to load hunspell dictionary for locale: " + locale, e);
103103
}
104104
};
105105
if (HUNSPELL_LAZY_LOAD.get(settings) == false) {

server/src/main/java/org/elasticsearch/rest/action/admin/indices/CreateIndexCapabilities.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ public class CreateIndexCapabilities {
2828

2929
private static final String NESTED_DENSE_VECTOR_SYNTHETIC_TEST = "nested_dense_vector_synthetic_test";
3030

31+
private static final String HUNSPELL_DICT_400 = "hunspell_dict_400";
32+
3133
public static final Set<String> CAPABILITIES = Set.of(
3234
LOGSDB_INDEX_MODE_CAPABILITY,
3335
LOOKUP_INDEX_MODE_CAPABILITY,
34-
NESTED_DENSE_VECTOR_SYNTHETIC_TEST
36+
NESTED_DENSE_VECTOR_SYNTHETIC_TEST,
37+
HUNSPELL_DICT_400
3538
);
3639
}

server/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testDicWithNoAff() throws Exception {
6464
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
6565
.build();
6666

67-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> {
67+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
6868
final Environment environment = new Environment(settings, getDataPath("/indices/analyze/no_aff_conf_dir"));
6969
new HunspellService(settings, environment, emptyMap()).getDictionary("en_US");
7070
});
@@ -78,7 +78,7 @@ public void testDicWithTwoAffs() throws Exception {
7878
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
7979
.build();
8080

81-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> {
81+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
8282
final Environment environment = new Environment(settings, getDataPath("/indices/analyze/two_aff_conf_dir"));
8383
new HunspellService(settings, environment, emptyMap()).getDictionary("en_US");
8484
});

0 commit comments

Comments
 (0)