Skip to content

Commit

Permalink
More safeguards to prevent missing config errors
Browse files Browse the repository at this point in the history
Thanks to Chris for the bug report!
  • Loading branch information
glutanimate committed Mar 6, 2017
1 parent b04ee91 commit 15a7790
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cloze_overlapper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ def setupValues(self, config):

def onAccept(self):
modified = False
config = loadConfig()
try:
modified = self.renameFields()
modified = self.renameFields(config)
except AnkiError: # rejected full sync warning
return
config = mw.col.conf['olcloze']
before = self.f.sb_before.value()
after = self.f.sb_after.value()
prompt = self.f.sb_cloze.value()
Expand All @@ -232,7 +232,7 @@ def onRestore(self):
def onReject(self):
self.close()

def renameFields(self):
def renameFields(self, config):
"""Check for modified names and rename fields accordingly"""
modified = False
model = mw.col.models.byName(OLC_MODEL)
Expand All @@ -241,7 +241,7 @@ def renameFields(self):
if not fnedit.isModified():
continue
name = fnedit.text()
oldname = mw.col.conf['olcloze']['flds'][key]
oldname = config['flds'][key]
if name is None or not name.strip() or name == oldname:
continue
idx = mw.col.models.fieldNames(model).index(oldname)
Expand All @@ -250,6 +250,6 @@ def renameFields(self):
# rename note type fields
mw.col.models.renameField(model, fld, name)
# update olcloze field-id <-> field-name assignment
mw.col.conf['olcloze']['flds'][key] = name
config['flds'][key] = name
modified = True
return modified
5 changes: 3 additions & 2 deletions cloze_overlapper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def onRemoveClozes(self):

def checkModel(model, fields=True, notify=True):
"""Sanity checks for the model and fields"""
config = mw.col.conf["olcloze"]
config = loadConfig()
mname = model["name"]
is_olc = False
# account for custom and imported note types:
Expand Down Expand Up @@ -332,7 +332,8 @@ def onAddNote(self, note, _old):
if not checkModel(note.model(), fields=False, notify=False):
return oldret
config = mw.col.conf["olcloze"]
if not config["sched"][2]:
sched_conf = config.get("sched", None)
if not sched_conf or not sched_conf[2]:
return oldret
maxfields = ClozeOverlapper.getMaxFields(note.model(), config["flds"]["tx"])
last = note.cards()[-1]
Expand Down

0 comments on commit 15a7790

Please sign in to comment.