Skip to content

Commit 1911a7d

Browse files
authored
Adjust exception thrown when unable to load hunspell dict (#123743) (#124146)
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: #123729 (cherry picked from commit a92b1d6)
1 parent d3d2d46 commit 1911a7d

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
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: []

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
@@ -214,3 +214,30 @@
214214
index.mode: lookup
215215
index.number_of_shards: 2
216216

217+
---
218+
"Create index with hunspell missing dict":
219+
- requires:
220+
test_runner_features: [ capabilities ]
221+
capabilities:
222+
- method: PUT
223+
path: /{index}
224+
capabilities: [ hunspell_dict_400 ]
225+
reason: "bugfix 'hunspell_dict_400' capability required"
226+
227+
- do:
228+
catch: bad_request
229+
indices.create:
230+
index: bad_hunspell_index
231+
body:
232+
settings:
233+
analysis:
234+
analyzer:
235+
en:
236+
tokenizer: standard
237+
filter:
238+
- my_en_US_dict_stemmer
239+
filter:
240+
my_en_US_dict_stemmer:
241+
type: hunspell
242+
locale: en_US
243+
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)