Describe the bug
With notes where Hanzi->Pinyin transcription fails, Zhuyin field filling causes Anki to crash (see exception below).
To Reproduce
Steps to reproduce the behavior:
Set up the addon with a note type containing a Hanzi and Ruby (Zhuyin) field
Make a card with the hanzi field "龴"
Attempt to auto-fill the Ruby field
See exception:
Caught exception:
File "/home/jon/.local/share/Anki2/addons21/1128979221/fill.py", line 186, in bulk_fill_transcript
fill_all_rubies(hanzi, copy)
File "/home/jon/.local/share/Anki2/addons21/1128979221/behavior.py", line 243, in fill_all_rubies
fill_ruby(hanzi, note, trans_group, ruby_group)
File "/home/jon/.local/share/Anki2/addons21/1128979221/behavior.py", line 214, in fill_ruby
split_hanzi(hanzi, grouped=True), 'bopomofo', 'trad'
File "/home/jon/.local/share/Anki2/addons21/1128979221/transcribe.py", line 88, in transcribe
transcribed.extend(bopomofo([s]))
File "/home/jon/.local/share/Anki2/addons21/1128979221/bopomofo.py", line 30, in bopomofo
print(replace_tone_marks(pinyin))
File "/home/jon/.local/share/Anki2/addons21/1128979221/transcribe.py", line 157, in replace_tone_marks
for bottom, top in separate_ruby(pinyin):
File "/home/jon/.local/share/Anki2/addons21/1128979221/ruby.py", line 106, in separate_ruby
for word in text
File "/home/jon/.local/share/Anki2/addons21/1128979221/ruby.py", line 106, in <listcomp>
for word in text
File "/home/jon/.local/share/Anki2/addons21/1128979221/ruby.py", line 95, in ruby_bottom
if not has_ruby(text):
File "/home/jon/.local/share/Anki2/addons21/1128979221/ruby.py", line 72, in has_ruby
return search(r'%s\[.+\]' % HANZI_REGEX, text)
File "/usr/lib/python3.6/re.py", line 182, in search
return _compile(pattern, flags).search(string)
<class 'TypeError'>: expected string or bytes-like object
Expected behavior
Safely fail (don't put anything in the Ruby field?)
Specs (please complete the following information):
Anki 2.1.11 (3cf770c7) Python 3.6.7 Qt 5.12.1 PyQt 5.11.3
Platform: Linux
Flags: frz=True ao=True sv=1
Add-ons possibly involved: Chinese Support Redux v0130
Additional context
I've debugged my end a little bit and found the exact culprit: Dictionary.get_pinyin returns None for this character, and this None input breaks the bopomofo transcription process. The code should safely fail instead.
Not sure how best to do that here. Happy to submit a PR if you let me know how this should be handled (error dialog? quiet failure? etc.).
Describe the bug With notes where Hanzi->Pinyin transcription fails, Zhuyin field filling causes Anki to crash (see exception below).
To Reproduce Steps to reproduce the behavior:
Expected behavior Safely fail (don't put anything in the Ruby field?)
Specs (please complete the following information):
Anki 2.1.11 (3cf770c7) Python 3.6.7 Qt 5.12.1 PyQt 5.11.3 Platform: Linux Flags: frz=True ao=True sv=1 Add-ons possibly involved: Chinese Support Redux v0130
Additional context
I've debugged my end a little bit and found the exact culprit:
Dictionary.get_pinyin
returnsNone
for this character, and thisNone
input breaks thebopomofo
transcription process. The code should safely fail instead.Not sure how best to do that here. Happy to submit a PR if you let me know how this should be handled (error dialog? quiet failure? etc.).
Thanks for the great addon!