Gustaf-C / anki-chinese-support-3

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1752008591
GNU General Public License v3.0
26 stars 7 forks source link

Bulk fill all error #16

Closed gdelmee closed 8 months ago

gdelmee commented 8 months ago

Running th Bulk fill All:

Anki 2.1.66 (70506aeb) Python 3.9.15 Qt 6.5.2 PyQt 6.5.2 Platform: Windows-10-10.0.19045 Flags: frz=True ao=True sv=2 Add-ons, last update check: 2023-11-02 09:28:02 Greffons possiblement impliqués : ⁨Chinese Support 3⁩

Caught exception: Traceback (most recent call last): File "C:\Users\ZZZZZ\AppData\Roaming\Anki2\addons21\1752008591\fill.py", line 96, in bulk_fill_all n_updated += update_fields(note, 'Hanzi', fields) File "C:\Users\ZZZZZ\AppData\Roaming\Anki2\addons21\1752008591\behavior.py", line 318, in update_fields fill_frequency(hanzi, copy) File "C:\Users\ZZZZZ\AppData\Roaming\Anki2\addons21\1752008591\behavior.py", line 250, in fill_frequency to=get_frequency(get_simp(hanzi)), File "C:\Users\ZZZZZ\AppData\Roaming\Anki2\addons21\1752008591\freq.py", line 44, in get_frequency res = match('[0-9]+ ([0-9.]+) %s$' % hanzi, line) File "re", line 191, in match File "re", line 304, in _compile File "sre_compile", line 788, in compile File "sre_parse", line 969, in parse re.error: unbalanced parenthesis at position 22

gdelmee commented 8 months ago

This is working for one package but not another one. First, I had a few cards on another note type. Then moving those away I was able to run the bulk fill on the working one. The second package I still can’t run it has only one note type with Hanzi field, and so on.

Gustaf-C commented 8 months ago

Would you mind uploading the deck that fails so I can do some investigating?

I had the same error a long time ago but I haven't been able to reproduce it since I forked the addon.

gdelmee commented 8 months ago

I’ve found the root cause!

It comes when there are parenthesis in my hanzi field: image Putting those in another package allowed me to run the bulk fill all on my package.

I don’t know why the regex match has an issue with parenthesis but maybe a try-catch mechanism could prevent such crashes.

Gustaf-C commented 8 months ago

Thanks for figuring out the cause, shouldn't be too hard to fix.