Skip to content

Commit a695907

Browse files
committed
handle potential exception
1 parent 8e45763 commit a695907

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

python/input_methods/hallelujah/ime_hallelujah.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,18 @@ def getSuggestionOfSpellChecker(self, input):
122122
alternatives = self.spellchecker.get_candidates(input)
123123
alternatives.sort(key=lambda x: x[0], reverse=True)
124124
candidates = [word for freq, word in alternatives]
125+
# If the input word is longer than 3 characters, add phonetic and Pinyin suggestions
125126
if len(input) > 3:
126-
encoded_key = fuzzySoundex.phonetics(input)
127-
phonetic_candidates = self.fuzzySoundexEncodedDict.get(encoded_key, [])
128-
phonetic_candidates.sort(key=lambda word: damerau_levenshtein_distance(word, input))
127+
phonetic_candidates = []
128+
try:
129+
encoded_key = fuzzySoundex.phonetics(input)
130+
phonetic_candidates = self.fuzzySoundexEncodedDict.get(encoded_key, [])
131+
phonetic_candidates.sort(key=lambda word: damerau_levenshtein_distance(word, input))
132+
except Exception as e:
133+
logger.error(f"Error generating phonetic key for '{input}': {e}")
134+
phonetic_candidates = [] # Ensure phonetic_candidates is an empty list if an error occurs
135+
129136
pinyin_candidates = self.pinyinDict.get(input, [])
130-
# logger.debug("phonetic_candidates {}", phonetic_candidates)
131137
candidates = candidates[:3] + pinyin_candidates[:3] + phonetic_candidates
132138
return candidates
133139

version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.11
1+
1.3.12

0 commit comments

Comments
 (0)