jdlorimer / chinese-support-redux

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

No notification when part of the data lookup step fails #122

Open ernop opened 4 years ago

ernop commented 4 years ago

anki 2.1.22 chinese support redux v0.13.0-beta with manual fix from here to fix initialization

Repro steps

What would resolve this?

If the data lookup times out or fails, there should be some kind of error message saying "upstream server doing meaning lookup at http://baidu.com~~~ failed, try again later"

jay-pee commented 4 years ago

I tried to reproduce this error by shutting down my internet connection before auto fill a new card: I got an error

Anki 2.1.15 (442df9d6) Python 3.8.3 Qt 5.12.5 PyQt 5.14.2
Platform: Linux
Flags: frz=False ao=True sv=1
Add-ons possibly involved: chinese-support-redux

Caught exception:
  File "/usr/share/anki/aqt/webview.py", line 27, in cmd
    return json.dumps(self.onCmd(str))
  File "/usr/share/anki/aqt/webview.py", line 87, in _onCmd
    return self._onBridgeCmd(str)
  File "/usr/share/anki/aqt/webview.py", line 386, in _onBridgeCmd
    return self.onBridgeCmd(cmd)
  File "/usr/share/anki/aqt/editor.py", line 272, in onBridgeCmd
    if runFilter(
  File "/usr/share/anki/anki/hooks.py", line 39, in runFilter
    arg = func(arg, *args)
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/edit.py", line 74, in onFocusLost
    if update_fields(note, field, allFields):
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/behavior.py", line 269, in update_fields
    fill_sound(hanzi, copy)
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/behavior.py", line 168, in fill_sound
    s = sound(hanzi, config['speech'])
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/sound.py", line 51, in sound
    return '[sound:%s]' % AudioDownloader(hanzi, source).download()
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/tts.py", line 50, in download
    self.func()
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/tts.py", line 56, in get_google
    tts.save(self.path)
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/lib/gtts/tts.py", line 243, in save
    self.write_to_fp(f)
  File "/home/jaypee/.local/share/Anki2/addons21/chinese-support-redux/lib/gtts/tts.py", line 186, in write_to_fp
    raise gTTSError(
<class 'gtts.tts.gTTSError'>: Connection error during token calculation: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fe1dbc470a0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

The TTS is failing not gracefully... so this might be another problem. I could not reproduce the problem from ernop. Can you give some more details on how to reproduce it? I think rather hard to debug because from the description it looks like some outside factors are accountable.

jdlorimer commented 4 years ago

At the very least, we should be catching that exception.

Something like the following would probably work:

from gtts.tts import gTTSError
...
try:
    tts.save(self.path)
except gTTSError:
    pass

A notification could be shown by replacing pass with aqt.utils.showInfo, but I'm not sure how intrusive that would be.