ttempe / chinese-support-addon

Addon for Anki2 that makes easier to input Chinese, in the spirit of batterseapower’s pinyin-toolkit for Anki1
https://github.com/ttempe/chinese-support-addon/wiki
47 stars 19 forks source link

Character causes plugin to fail #62

Open MolotovCherry opened 8 years ago

MolotovCherry commented 8 years ago

Note: I got these characters from a course on memrise. I suspect that there's something different with these characters which are causing these strange problems. Consequently, I also cannot use the fill in missing fields feature, probably because of this.

A certain character, ⺌, ⺍ (not sure why this one is a box, try putting it in Google Translator and the character will show up. English->Chinese), is causing the plugin to fail for me.

The error happens when I am in the browser and viewing all my cards. I enable the plugin by clicking the button, click the Hanzi field, then click the next field, and this error pops up.

An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons

Traceback (most recent call last):
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.webview", line 18, in run
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.editor", line 462, in bridge
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/anki.hooks", line 32, in runFilter
  File "D:\Users\user\Documents\Anki\addons\chinese\edit.py", line 47, in on_focus_lost
    edit_behavior.update_fields(efields, updated_field, model_name, model_type)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 523, in update_fields
    update_all_Transcription_fields(field[updated_field], field)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 271, in update_all_Transcription_fields
    update_Bopomofo_fields(hanzi, dico)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 258, in update_Bopomofo_fields
    t = colorize( transcribe( no_sound( hanzi ), "Bopomofo") )
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_functions.py", line 270, in transcribe
    r = bopomofo_module.bopomofo(no_accents(r))
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_functions.py", line 162, in no_accents
    if len(text)==0:
TypeError: object of type 'NoneType' has no len()

Another character (龵) (yes, the character looks blank for some reason; paste it into Google translate) causes it to fail with a different error:

An error occurred in an add-on.
Please post on the add-on forum:
https://anki.tenderapp.com/discussions/add-ons

Traceback (most recent call last):
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.webview", line 18, in run
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.editor", line 462, in bridge
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/anki.hooks", line 32, in runFilter
  File "D:\Users\user\Documents\Anki\addons\chinese\edit.py", line 47, in on_focus_lost
    edit_behavior.update_fields(efields, updated_field, model_name, model_type)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 523, in update_fields
    update_all_Transcription_fields(field[updated_field], field)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 267, in update_all_Transcription_fields
    update_Transcription_fields(hanzi, dico)
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_behavior.py", line 187, in update_Transcription_fields
    t = colorize( transcribe( no_sound( hanzi ) ) )
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_functions.py", line 56, in colorize
    text = re.sub(u'([\u3400-\u9fff])', colorize_hanzi_sub, text)
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/re", line 151, in sub
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_functions.py", line 37, in colorize_hanzi_sub
    return u'<span class="tone{t}">{r}</span>'.format(t=get_tone_number(transcribe(p.group(1), only_one=True)), r=p.group())
  File "D:\Users\user\Documents\Anki\addons\chinese\edit_functions.py", line 636, in get_tone_number
    if re.match(r".+1[0-9]$", pinyin):
  File "C:\cygwin\home\dae\win\build\pyi.win32\anki\outPYZ1.pyz/re", line 137, in match
TypeError: expected string or buffer
MolotovCherry commented 8 years ago

Even if there's not supposed to be any support for characters such as this, due to them not being standard or something, it's still very bad that the plugin is failing with various kinds of errors because of it.

leezu commented 8 years ago

I'm getting a similar error with some letters (e.g. 㣽, 㚢). Actually I was just trying to figure out how to type the u umlaut (ü) character to write the letter 女.

After several tries with those erroneous characters Anki gave errors as well when I tried to enter 女. Only restart of the program made it work again.

Traceback: Traceback (most recent call last): File "/usr/share/anki/aqt/progress.py", line 69, in handler func() File "/usr/share/anki/aqt/editor.py", line 466, in onUpdate self.loadNote() File "/usr/share/anki/anki/hooks.py", line 55, in repl old(_args, *_kwargs) File "/usr/share/anki/aqt/editor.py", line 538, in loadNote data.append((fld, self.mw.col.media.escapeImages(val))) File "/usr/share/anki/anki/media.py", line 237, in escapeImages string = re.sub(reg, repl, string) File "/usr/lib/python2.7/re.py", line 155, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: expected string or buffer