Ajatt-Tools / anki.koplugin

KOReader plugin enabling Anki card generations for words looked up in the internal dictionary.
49 stars 6 forks source link

Koreader crashes after adding a lot of offline cards. #19

Closed DandyMountainLion closed 5 months ago

DandyMountainLion commented 5 months ago

Hello, first of all thank you for the plugin, it looks fantastic!

Second, here is the problem: My ereader had the wifi off and I was adding a bunch of cards offline (as I have not yet successed in connecting the ereader with Anki) when all of a sudden Koreader crashed. I did not manage to get a picture before the error disappeared but I noticed that the plugin was not working anymore (the Add to Anki button had disappeared).

But here is what the crash.log file says (Huge wall of text)
03/20/24-18:19:05 INFO  (re)initializing context buffer with size: 50 
03/20/24-18:19:05 INFO  after reinit: prev table = 54, next table = 54 
03/20/24-18:19:05 INFO  AnkiNote#get_custom_context() 1 0 1 0 
03/20/24-18:19:14 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:19:17 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:19:21 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:19:46 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:20:06 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:20:20 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:20:23 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:20:30 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:20:42 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:23:37 ERROR Failed to initialize anki plugin: plugins/anki.koplugin/ankiconnect.lua:277: attempt to index local 'note' (a nil value) 
03/20/24-18:23:39 INFO  opening file /mnt/onboard/神去なあなあ日常 -- 三浦しをん.epub 
03/20/24-18:23:39 INFO  Inhibiting user input 
03/20/24-18:23:39 ERROR Failed to initialize anki plugin: plugins/anki.koplugin/ankiconnect.lua:277: attempt to index local 'note' (a nil value) 
03/20/24-18:23:40 INFO  Restoring user input handling 
03/20/24-18:25:31 INFO  Inhibiting user input 
03/20/24-18:25:31 INFO  Restoring user input handling 
03/20/24-18:25:33 INFO  Inhibiting user input 
03/20/24-18:25:33 INFO  Restoring user input handling 
03/20/24-18:26:22 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:27:00 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:27:07 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:27:17 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
03/20/24-18:27:38 WARN  unwrapped dismissablePopen(), falling back to blocking io.popen() 
g_mkdir failed: No such file or directory
g_mkdir failed: No such file or directory
./luajit: plugins/anki.koplugin/ankinote.lua:45: attempt to index field 'document' (a nil value)
stack traceback:
    plugins/anki.koplugin/ankinote.lua:45: in function 'fn'
    plugins/anki.koplugin/ankinote.lua:172: in function 'build'
    plugins/anki.koplugin/ankiconnect.lua:224: in function 'add_note'
    plugins/anki.koplugin/main.lua:175: in function 'callback'
    frontend/ui/widget/buttontable.lua:81: in function 'callback'
    frontend/ui/widget/button.lua:472: in function 'handleEvent'
    frontend/ui/widget/container/inputcontainer.lua:266: in function 'handleEvent'
    frontend/ui/widget/container/widgetcontainer.lua:83: in function 'propagateEvent'
    frontend/ui/widget/container/widgetcontainer.lua:101: in function 'handleEvent'
    frontend/ui/widget/container/widgetcontainer.lua:83: in function 'propagateEvent'
    frontend/ui/widget/container/widgetcontainer.lua:101: in function 'handleEvent'
    ...
    frontend/ui/widget/container/widgetcontainer.lua:101: in function 'handleEvent'
    frontend/ui/widget/container/widgetcontainer.lua:83: in function 'propagateEvent'
    frontend/ui/widget/container/widgetcontainer.lua:101: in function 'handleEvent'
    frontend/ui/uimanager.lua:907: in function 'sendEvent'
    frontend/ui/uimanager.lua:53: in function '__default__'
    frontend/ui/uimanager.lua:1436: in function 'handleInputEvent'
    frontend/ui/uimanager.lua:1536: in function 'handleInput'
    frontend/ui/uimanager.lua:1580: in function 'run'
    ./reader.lua:280: in main chunk
    [C]: at 0x000140cd
!!!!
Uh oh, something went awry... (Crash n°1: 03/20/24 @ 18:28:02)
Running FW 4.38.21908 on Linux 4.1.15-00866-g3a75628c73c (#96 SMP PREEMPT Thu Nov 17 14:25:47 CST 2022)
Attempting to restart KOReader . . .
!!!!

After seeing the "attempt to index local 'note' (a nil value)' error, I also looked at the anki.koplugin_notes.json file and there is two notes with a different format: image So I guess a short term answer would be to clear the file but the problem remains.

I think there may be an error in the config.lua file since I also can't connect but I don't seem to find it. image I wrote the url variable like this: url = "http://IPv4:8765" (IPv4 being my IP address of course.) Maybe it is the space in "Word Audio" ?

If you have any idea that would be great, thank you!

nairyosangha commented 5 months ago

your URL is fine, I'd be curious to know what the error is you getwhen you're trying to add a note while the wifi is on

As to your other issue, I'm a bit confused by the log 03/20/24-18:23:37 ERROR Failed to initialize anki plugin: plugins/anki.koplugin/ankiconnect.lua:277: attempt to index local 'note' (a nil value) One of the notes that are stored locally in anki.koplugin_notes.json must be corrupted. Looking at your screenshot it seems fine to me at first glance, it doesn't really matter whether "params" or "version" is listed first, as long as they're both present. The fact that note is nil means one of them must be invalid JSON, hard for me to tell which one unless you post the file, you could try and remove them one after another until it works :smile:

I don't get how you first run into that 'attempt to index local 'note'' issue, but then still manage to create a note at some later point. If the button disappeared, how were you able to add a note?

./luajit: plugins/anki.koplugin/ankinote.lua:45: attempt to index field 'document' (a nil value) This happened while it was trying to get the metadata for whatever document you were reading, somehow this document wasn't present. This is initialized by KOreader itself, so I can't really tell why it might've been missing for you there

DandyMountainLion commented 5 months ago

Thanks for the fast reply ! 😄

I don't get how you first run into that 'attempt to index local 'note'' issue, but then still manage to create a note at some later point. If the button disappeared, how were you able to add a note?

The weird thing is that I wasn't getting any errors while adding the cards and the button only disappeared after the crash when Koreader restarted

I'd be curious to know what the error is you getwhen you're trying to add a note while the wifi is on

To be able have the button back and to screenshot the error, I had to clear the anki.koplugin_notes.json file so I have joined it before the clear, in case you are still curious about it (I made a copy in case the issue is fixed and the cards can be salvaged but if it's not possible that's also okay) anki.koplugin_notes.json

Here is the screenshot of the error when the Wifi is on: Reader_2024-03-20_225927 If I understood correctly it comes from an error due to misconfiguration of IP/port ?

Here is my AnkiConnect config:

{
    "apiKey": null,
    "apiLogPath": null,
    "ignoreOriginList": [],
    "webBindAddress": "0.0.0.0",
    "webBindPort": 8765,
    "webCorsOriginList": [
        "http://localhost"
    ]
}

What I tried:

nairyosangha commented 5 months ago

To be able have the button back and to screenshot the error, I had to clear the anki.koplugin_notes.json file so I have joined it before the clear, in case you are still curious about it (I made a copy in case the issue is fixed and the cards can be salvaged but if it's not possible that's also okay)

On line 4 you have 2 JSON strings on a single line, that's the one it's failing on, this should just be:

{"version":6,"action":"addNote","params":{"note":{"options":{"duplicateScope":"deck","allowDuplicate":false},"tags":["KOReader"],"deckName":"日本語","_field_callbacks":{"audio":{"args":["掃除","ja"],"func":"set_forvo_audio"},"picture":{"args":{},"func":"set_image_data"}},"fields":{"Sentence":"<b>掃除</b>機がかけられないので、困ります) と立ち話をしていたりするが、最初はなに言ってんだかよく聞き取れなかった。","Definitions":"<div class=\"definition\"><ol><li dict=\"スーパー大辞林 3.0\">そう じ (さうぢ) [0]【掃除】<br>(名)スル<br>①掃いたりふいたりして,ごみや汚れをなくしてきれいにすること。「部屋を―する」「―機」<br>②害悪を除き去ること。「悪の温床を―する」<br>③便所の糞尿を汲み取ること。</li></ol></div>","Notes":"三浦しをん - 神去なあなあ日常 (6/362)","Expression":"掃除"},"modelName":"Word card Japanese"}}}
{"params":{"note":{"_field_callbacks":{"picture":{"func":"set_image_data","args":{}},"audio":{"func":"set_forvo_audio","args":["俗信","ja"]}},"deckName":"日本語","options":{"allowDuplicate":false,"duplicateScope":"deck"},"modelName":"Word card Japanese","tags":["KOReader"],"fields":{"Notes":"三浦しをん - 神去なあなあ日常 (7/362)","Expression":"俗信","Sentence":"俗信","Definitions":"<div class=\"definition\"><ol><li dict=\"スーパー大辞林 3.0\">ぞく しん [0]【俗信】<br>日常生活を左右するものとして,世間で広く信じられてきた言い伝えや迷信。禁忌・予兆・占卜(せんぼく)・呪術・諺(ことわざ)・憑(つ)き物・妖怪など。「病気についての―」</li></ol></div>"}}},"action":"addNote","version":6}

Just curious, did you use the 'delete latest note' option at any point while creating these notes? I think there might be a bug there for offline stored notes

As for your connection issue: your anki-connect config looks fine, if you can't use curl then just use wget, that should work just as well. The fact that you can't ping the IPv4 address is weird, that really should work. If you can't ping nor wget http://<IP>:8765 then it's not gonna work in the plugin either.

The fact you're getting a timeout and not a 'connection refused' makes me suspect you're using the wrong IP, and it's not a firewall issue

nairyosangha commented 5 months ago

I managed to reproduce the issue with the 2 notes ending up on 1 line and I've pushed a fix

DandyMountainLion commented 5 months ago

I managed to reproduce the issue with the 2 notes ending up on 1 line and I've pushed a fix

That's great news! I probably did try the delete button like you said.

your anki-connect config looks fine, if you can't use curl then just use wget, that should work just as well. The fact that you can't ping the IPv4 address is weird, that really should work.

Following that idea I tried to change network to make sure the ereader was exactely on the same network as my PC and I got this error (which I remember also getting before)

FileManager_2024-03-21_203905 Still curious that the ping 1.1.1.1 still worked then.

I even though I installed KoReader with the OCP-KOReader-v2024.03.1.zip folder and script so that might be the problem...I know it's going outside of the plugin scope but in case someone has the same error, I feel it's still appropriate to post it. I'm trying to reinstall Koreader as of now. (Do you have the same version/did you also installed it with the OPC mechanism?)

nairyosangha commented 5 months ago

Yeah that's definitely out of scope here, I have no idea what could be wrong. I'm currently still on v2023.04. I did find this comment which sounds similar to what you're having, and it's fixed by not using that OCP install method.

I used the linux script linked in this post to install from the zip specific for my device, which I got straight from the koreader releases on github

nairyosangha commented 5 months ago

There's also a comment saying just turning the reader off and on again fixes it, classic :smile:

DandyMountainLion commented 5 months ago

There's also a comment saying just turning the reader off and on again fixes it, classic 😄 Ah yes, the magical solution that works 8 times out of 10 haha

Sadly, that didn't work but since this isn't linked to the plugin and the one line two cards bug is fixed I should close this issue!

Thank you very much your help. 😄