chinese-support-redux icon indicating copy to clipboard operation
chinese-support-redux copied to clipboard

No notification when part of the data lookup step fails

Open ernop opened this issue 6 years ago • 2 comments

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

Repro steps

  • paste in hanzi into hanzi field
  • hit tab to fill in values
  • most values fill in
  • but occasionally the english part fails and remains blank. This was a periodic issue throughout 4/19. Later in the day it resolved without any change.
  • I assume there was a timeout on the call, but there was no notification and I spent a long time trying to debug what was going on.

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"

ernop avatar Apr 20 '20 15:04 ernop

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.

jay-pee avatar Jun 08 '20 16:06 jay-pee

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.

jdlorimer avatar Jun 08 '20 22:06 jdlorimer