z1lc / AutoDefine

An add-on to Anki that auto-defines words, optionally adding pronunciation and images.
https://ankiweb.net/shared/info/2136497008
GNU General Public License v2.0
58 stars 17 forks source link

autodefine: Fix insert_into_field bounds checking #44

Closed mancasg closed 3 years ago

mancasg commented 3 years ago

Hello,

I'm a new Anki user and I just installed the autodefine plugin, and immediately stumbled into a somewhat minor issue. I tried to autodefine a word, along with the pronunciation (on field 2), using the default, 2 fields card. Upon this the plugin crashes with the following report:

Error 
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed. 
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem. 
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site. 
Debug info:
Anki 2.1.35 (84dcaa86) Python 3.8.0 Qt 5.14.2 PyQt 5.14.2
Platform: Mac 10.15.6
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-11-07 18:14:55
Add-ons possibly involved: ⁨AutoDefine - Automatically define vocabulary words with pronunciations and image⁩

Caught exception:
Traceback (most recent call last):
  File "aqt/webview.py", line 493, in handler
  File "aqt/editor.py", line 483, in <lambda>
  File "/Users/georgem/Library/Application Support/Anki2/addons21/2136497008/autodefine.py", line 100, in <lambda>
    editor.saveNow(lambda: _get_definition(editor, force_pronounce, force_definition, force_phonetic_transcription))
  File "/Users/georgem/Library/Application Support/Anki2/addons21/2136497008/autodefine.py", line 309, in _get_definition
    insert_into_field(editor, to_print, PHONETIC_TRANSCRIPTION_FIELD)
  File "/Users/georgem/Library/Application Support/Anki2/addons21/2136497008/autodefine.py", line 413, in insert_into_field
    editor.note.fields[field_id] += text
IndexError: list index out of range

This is caused by a bounds checking issue, fixed in the current patch.

Thanks for the plugin!

z1lc commented 3 years ago

Uploaded new version to AnkiWeb.