Skip to content

Commit e638262

Browse files
committed
Make the spell check wrapper more robust, solves #933
1 parent 5ca8815 commit e638262

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

novelwriter/core/spellcheck.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,26 @@ def setLanguage(self, theLang, projectDict=None):
7575
def checkWord(self, theWord):
7676
"""Wrapper function for pyenchant.
7777
"""
78-
return self.theDict.check(theWord)
78+
try:
79+
return self.theDict.check(theWord)
80+
except Exception:
81+
return True
7982

8083
def suggestWords(self, theWord):
8184
"""Wrapper function for pyenchant.
8285
"""
83-
return self.theDict.suggest(theWord)
86+
try:
87+
return self.theDict.suggest(theWord)
88+
except Exception:
89+
return []
8490

8591
def addWord(self, newWord):
8692
"""Add a word to the project dictionary.
8793
"""
88-
self.theDict.add_to_session(newWord)
94+
try:
95+
self.theDict.add_to_session(newWord)
96+
except Exception:
97+
return False
8998

9099
if self.projectDict is not None and newWord not in self.projDict:
91100
newWord = newWord.strip()

tests/test_core/test_core_spell.py renamed to tests/test_core/test_core_spellcheck.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ def testCoreSpell_Enchant(monkeypatch, tmpDir):
4848
assert spChk.listDictionaries() == []
4949
assert spChk.describeDict() == ("", "")
5050

51+
# Break the enchant package, and check error handling
52+
spChk = NWSpellEnchant()
53+
spChk.theDict = None
54+
assert spChk.checkWord("word") is True
55+
assert spChk.suggestWords("word") == []
56+
assert spChk.addWord("word") is False
57+
5158
# Load the proper enchant package (twice)
5259
spChk = NWSpellEnchant()
5360
spChk.setLanguage("en", wList)

0 commit comments

Comments
 (0)