obynio / anki-japanese-furigana

Anki add-on providing support for adding furigana on Japanese text
https://ankiweb.net/shared/info/678316993
GNU General Public License v3.0
19 stars 7 forks source link

Not working with error #10

Open IstoraMandiri opened 2 years ago

IstoraMandiri commented 2 years ago

Tried using this with Anki 2.1.50 on Linux and while the buttons appear they do not do anything and no furigana is generated.

When closing the Card Browser the following error occurs:

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.50 (26d40c3a) Python 3.9.10 Qt 5.15.2 PyQt 5.15.5
Platform: Linux
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-04-30 07:16:44
Add-ons possibly involved: ⁨678316993⁩

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'

Caught exception:
Traceback (most recent call last):
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
  File "/home/tora/.var/app/net.ankiweb.Anki/data/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
AttributeError: 'NoneType' object has no attribute 'page'
rehaby commented 2 years ago

I'm getting the same error using the latest flatpak version (2.1.50) in linux. Looking at the releases page, that version isn't a stable release version as 2.1.49 was the previous stable release compared to the current 2.1.51

rehaby commented 2 years ago

It works on 2.1.49 but not on 2.1.51, using the linux download from the anki website

obynio commented 2 years ago

Damn sorry I did not see the issue notification. I'll try to take a look asap and see what's going on.

neko-cha commented 2 years ago

Hello,

This error occurs with the latest version 2.1.54 (b6a7760c)⁩.

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.54 (b6a7760c) Python 3.9.10 Qt 6.3.1 PyQt 6.3.1
Platform: Linux
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-09-04 14:08:03
Add-ons possibly involved: ⁨JapaneseFurigana⁩

Caught exception:
Traceback (most recent call last):
  File "/home/neko-cha/.local/share/Anki2/addons21/678316993/__init__.py", line 110, in <lambda>
    self.window.web.page().runJavaScript("getCurrentField().fieldHTML", lambda x: self.setHtml(x, callback, True))
  File "/home/neko-cha/.local/share/Anki2/addons21/678316993/__init__.py", line 110, in setHtml
    self.window.web.page().runJavaScript("getCurrentField().fieldHTML", lambda x: self.setHtml(x, callback, True))
AttributeError: 'NoneType' object has no attribute 'page'
zessx commented 2 years ago

Waiting for the fix, you can revert Anki to 2.1.49 on macOS with the following commands (using Homebrew):

brew uninstall anki
curl -o ./anki.rb https://raw.githubusercontent.com/Homebrew/homebrew-cask/4d7a52944e2903a4c3a9a5b5dc7622a0e32204e5/Casks/anki.rb
brew install --cask ./anki.rb
rm anki.rb

Your plugins will be preserved.

obynio commented 2 years ago

It appears Anki moved to Qt6 in the latest releases, there might be some breaking changes...

obynio commented 2 years ago

Okay it appears you now need to use AnkiWebView() to access the webpage...

obynio commented 2 years ago

Well even with something like this it does not appear to work. The update may have broken something else and it needs further investigations...

wv = AnkiWebView()
if self.isDeprecated():
    wv.eval("setFormat('selectAll');")
    wv.page().runJavaScript(self.js_get_html, lambda x: self.setHtml(x, callback, True))
else:
    wv.page().runJavaScript("getCurrentField().fieldHTML", lambda x: self.setHtml(x, callback, True))
obynio commented 2 years ago

This issue should be fixed in the latest release, feel free to reopen this issue if it's still not working.

zessx commented 2 years ago

It seems to work on new cards (addition and removal), but I already had an issue trying to remove furigana from an old card:

Anki and this plugin are up-to-date.

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.54 (b6a7760c) Python 3.9.7 Qt 6.3.1 PyQt 6.3.1
Platform: Mac 12.3
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-09-26 19:40:45
Add-ons possibly involved: ⁨JapaneseFurigana⁩

Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 42, in cmd
  File "aqt.webview", line 149, in _onCmd
  File "aqt.webview", line 624, in _onBridgeCmd
  File "aqt.editor", line 467, in onBridgeCmd
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/__init__.py", line 49, in <lambda>
    editor._links["deleteFurigana"] = lambda ed=editor: doIt(ed, deleteFurigana)
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/__init__.py", line 56, in doIt
    Selection(editor, lambda s: action(editor, s))
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/selection.py", line 43, in __init__
    self.setHtml(None, callback)
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/selection.py", line 64, in setHtml
    self.setHtml(self.window.note.fields[self.window.currentField], callback, True)
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/selection.py", line 49, in setHtml
    callback(self)
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/__init__.py", line 56, in <lambda>
    Selection(editor, lambda s: action(editor, s))
  File "/Users/samuel/Library/Application Support/Anki2/addons21/678316993/__init__.py", line 75, in deleteFurigana
    replacement = re.search(r"<ruby>(.*?)<rp>",b).group(1).strip()
AttributeError: 'NoneType' object has no attribute 'group'
obynio commented 2 years ago

@zessx I can't reproduce the bug with just the stacktrace, can you provide the HTML code of the card that do not work ?

obynio commented 2 years ago
Screen Shot 2022-09-27 at 16 15 25

Click this button and send me the HTML notation of the card that do not works

zessx commented 2 years ago

Unfortunately, I don't have this code anymore as I fixed the card by removing ruby tags manually, before re-adding furigana. I tried to find other broken cards without success, but I think I understood my issue.

The card was containing AとBの間に, with being spelled by this plugin. As I wanted to correct it to あいだ, I manually (months ago) fixed the card in the visual editor (and NOT via the code editor). I think I simply may have broke ruby tags (missing close tag or anything like that).

You can close back this issue, I'm pretty sure this is not a real issue we should care about. Sorry for the disturbance, and thanks for your work 👍

obynio commented 2 years ago

Yeah that's the reason why I set the bracket notation as the default one in this plugin. Ruby tags are a struggle to parse and process but they were added to Anki at a time when there was no support for bracket notation.

I'll close the issue, feel free to leave a comment here if any issue arise in the latest release.

Cloverlimit commented 1 year ago

Hi--I got this error when trying to add furigana to kanji:

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.54 (b6a7760c) Python 3.9.7 Qt 5.15.2 PyQt 5.15.5
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-11-21 21:16:46

Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 42, in cmd
  File "aqt.webview", line 149, in _onCmd
  File "aqt.webview", line 624, in _onBridgeCmd
  File "aqt.editor", line 467, in onBridgeCmd
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 47, in <lambda>
    editor._links["generateFurigana"] = lambda ed=editor: doIt(ed, generateFurigana)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in doIt
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 43, in __init__
    self.setHtml(None, callback)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 64, in setHtml
    self.setHtml(self.window.note.fields[self.window.currentField], callback, True)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 49, in setHtml
    callback(self)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in <lambda>
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 60, in generateFurigana
    html = mecab.reading(html, config.getIgnoreNumbers(), config.getUseRubyTags())
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\reading.py", line 212, in reading
    self.mecab.stdin.flush()
OSError: [Errno 22] Invalid argument
ahlec commented 1 year ago

Hi--I got this error when trying to add furigana to kanji:

What sentence/field were you trying to run this on? Could you give us a sample of the input you were trying to add furigana to?

Also, was this when you were adding a new card, or when you were editing an existing card?

Cloverlimit commented 1 year ago

I was creating a new card using the default settings and was entering in 今 or 今日 (I tried more than one time) to the Front field. Sometimes it would blank the field entirely when I clicked the furigana button, and other times it would just throw up the error provided above.

I hope that's of use!

obynio commented 1 year ago

Well that's strange but that's not enough to reproduce the bug, so nothing I can do, sorry :/

ahlec commented 1 year ago

Ack, sorry for the late reply; the holiday week has my schedule messed up.

I checked out the error code, and it looks like the cause might be from the Mecab subprocess closing early (perhaps there was an error from within Mecab that we aren't subscribed to/reporting, so it went undetected), or from the Mecab subprocess not being fully open (we started the subprocess then instantaneously made calls to use it).

I had thought that we opened the subprocess the moment Anki starts up, and then we leave it open, but it actually looks like we don't open it until the first time we need to get a reading. So potentially either of these causes could be a possibility. I'm not totally sure on how to reproduce either of them, though. I've done a bunch of testing in the past and never seen this, so it must be either rare, or on an environment I don't test in (it does look like the bug is from Windows, maybe that's part of it?)

@Cloverlimit When you close Anki and reopen it, do you still get the same error? Does it happen every time you try to use the plugin?

Cloverlimit commented 1 year ago

@Cloverlimit When you close Anki and reopen it, do you still get the same error? Does it happen every time you try to use the plugin?

Strangely, when I booted it up just now, it suddenly worked for the first time and I was about to mark this as fixed (the only change had been I had finally set up my AnkiWeb account and synced the app to it), but I was skeptical, so I restarted the app and it stopped working again.

Here's more detailed repro steps:

  1. Open Anki desktop app and click on any deck
  2. Add card (custom or default Basic)
  3. Type hiragana into the Front field and hit Space to convert to kanji
  4. Hit enter to confirm kanji choice
  5. Highlight kanji and click on the furigana+ button
  6. Front field is blanked out (kanji disappears) with no accompanying error
  7. Redo steps 3-5
  8. Error message every time afterwards
Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.54 (b6a7760c) Python 3.9.7 Qt 5.15.2 PyQt 5.15.5
Platform: Windows 10
Flags: frz=True ao=True sv=2
Add-ons, last update check: 2022-11-24 19:00:05

Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 42, in cmd
  File "aqt.webview", line 149, in _onCmd
  File "aqt.webview", line 624, in _onBridgeCmd
  File "aqt.editor", line 467, in onBridgeCmd
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 47, in <lambda>
    editor._links["generateFurigana"] = lambda ed=editor: doIt(ed, generateFurigana)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in doIt
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 43, in __init__
    self.setHtml(None, callback)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 64, in setHtml
    self.setHtml(self.window.note.fields[self.window.currentField], callback, True)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 49, in setHtml
    callback(self)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in <lambda>
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 60, in generateFurigana
    html = mecab.reading(html, config.getIgnoreNumbers(), config.getUseRubyTags())
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\reading.py", line 212, in reading
    self.mecab.stdin.flush()
OSError: [Errno 22] Invalid argument
ahlec commented 1 year ago

The first time you run it, when it completely blanks out the field, seems super suspect. If I had to guess, there might be some kind of error that's happening which we're not subscribed to, and it might be closing the Mecab process. Looking at the code, it looks like all we're doing is writing errors to stdout, rather than listening for them/allowing them to become Python errors that could be reported to us directly. We should probably fix that, even if it doesn't fix this issue directly.

I'd be curious if you're able to see anything by running Anki from the command line. It would allow you to see all of the output, including (possibly) something that Mecab might be trying to tell us. If you're running on a traditional Windows machine using the default Command Prompt, you should be able to do:

cd C:\Path\To\Anki
start Anki.exe

For the first command, you'll need to find the exact directory that has your exe in it, and the second command, you'll need to use the exact filename. When you have Anki open, if you right click on the icon in the task bar and view properties or something, it should give you a screen that shows you the exact command to run. You could actually maybe just paste that directly into the Command Prompt? Or, start <the whole path including the .exe>.

Cloverlimit commented 1 year ago

Didn't work the first time from command line, then worked the second time, then not the third. Command Prompt spat out a familiar error:

C:\Program Files\Anki>Anki starting...
Initial setup...
Preparing to run...
Starting main loop...
Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 42, in cmd
  File "aqt.webview", line 149, in _onCmd
  File "aqt.webview", line 624, in _onBridgeCmd
  File "aqt.editor", line 467, in onBridgeCmd
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 47, in <lambda>
    editor._links["generateFurigana"] = lambda ed=editor: doIt(ed, generateFurigana)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in doIt
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 43, in __init__
    self.setHtml(None, callback)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 64, in setHtml
    self.setHtml(self.window.note.fields[self.window.currentField], callback, True)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\selection.py", line 49, in setHtml
    callback(self)
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 55, in <lambda>
    Selection(editor, lambda s: action(editor, s))
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\__init__.py", line 60, in generateFurigana
    html = mecab.reading(html, config.getIgnoreNumbers(), config.getUseRubyTags())
  File "C:\Users\Cloverlimit\AppData\Roaming\Anki2\addons21\678316993\reading.py", line 212, in reading
    self.mecab.stdin.flush()
OSError: [Errno 22] Invalid argument

No clue why the video quality on this was garbage from OBS, but you can see exactly what I do each time I'm testing.