Skip to content

Commit d9c9cba

Browse files
Merge 9b28b31 into 5a0b42e
2 parents 5a0b42e + 9b28b31 commit d9c9cba

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

source/speechDictHandler/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def sub(self, text):
4747

4848
class SpeechDict(list):
4949

50+
fileName = None
51+
5052
def load(self, fileName):
5153
self.fileName=fileName
5254
comment=""
@@ -98,8 +100,16 @@ def save(self,fileName=None):
98100
file.close()
99101

100102
def sub(self, text):
101-
for entry in self:
102-
text = entry.sub(text)
103+
invalidEntries=[]
104+
for index,entry in enumerate(self):
105+
try:
106+
text = entry.sub(text)
107+
except re.error as exc:
108+
dictName=self.fileName or "temporary dictionary"
109+
log.error(f"Invalid dictionary entry {index+1} in {dictName}: \"{entry.pattern}\", {exc}")
110+
invalidEntries.append(index)
111+
for index in reversed(invalidEntries):
112+
del self[index]
103113
return text
104114

105115
def processText(text):

0 commit comments

Comments
 (0)