[Bug] TypeError: argument of type "NoneType" is not iterable
KOreader Sync plugin version
0.6.8
KOreader version
2024.11
Operating System
Linux
Connection type
Wired (over usb cable)
Describe the bug
Attempting to sync, after a length of time get popup with heading error.
How to reproduce
Running KOReader under Android. Connection via USB. Calibre ebook folder is on an microSD card mounted as an mtp device and is accessed via Calibre "Connect/Share".
After "On Device" is refreshed, press "KOReader Sync". After awhile, the application halts with the popup dialogue..
Expected behavior
Updated KOReader Sync stats.
Provide details output from plugin pop-up window
calibre, version 7.23.0
ERROR: Unhandled exception: <b>TypeError</b>:argument of type 'NoneType' is not iterable
calibre 7.23 embedded-python: False
Linux-6.12.17_1-x86_64-with-glibc2.39 Linux ('64bit', 'ELF')
('Linux', '6.12.17_1', '#1 SMP PREEMPT_DYNAMIC Tue Mar 4 23:20:38 UTC 2025')
Python 3.13.2
Interface language: None
EXE path: /usr/bin/python3
Successfully initialized third party plugins: Gather KFX-ZIP (from KFX Input) (1, 49, 0) && Package KFX (from KFX Input) (1, 49, 0) && Apple Books covers (0, 1, 0) && Count Pages (1, 13, 6) && Goodreads (1, 8, 2) && KFX metadata reader (from KFX Input) (1, 49, 0) && KFX Input (1, 49, 0) && KOReader Sync (0, 6, 8) && Kindle hi-res covers (0, 5, 1) && Kobo Books (1, 9, 2) && Kobo Metadata (1, 5, 0) && Kobo Utilities (2, 16, 13) && KoboTouchExtended (3, 6, 7) && Obok DeDRM (10, 0, 3)
Traceback (most recent call last):
File "calibre_plugins.koreader.action", line 793, in sync_to_calibre
sidecar_contents = self.get_sidecar(device, sidecar_path)
File "calibre_plugins.koreader.action", line 376, in get_sidecar
parsed_contents = parse_sidecar_lua(decoded_contents)
File "calibre_plugins.koreader.action", line 126, in parse_sidecar_lua
if 'bookmarks' in decoded_lua:
^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
Screenshots
No response
Any additional info
Running KOReader under Android. Connection via USB. Calibre ebook folder is on a microSD card with Android device mounted via mtp.
Problem DOES NOT occur with KOReader instance on Calibre/Kobo pairing.
Interesting.... if this Android specific how can I reproduce this issue? Android emulator with KOreader? Not sure where to start any help will be appreciated
@sdothum can you try to reproduce it on new latest release? (v0.7.0)
Got same error.
Don't remember the progress bar from before (which if new, is a nice touch). Progress stops at book which, if removed from the device, fails with same error on "next" book (uncertain what constitutes next book in scan)..
calibre, version 7.23.0 ERROR: Unhandled exception: TypeError:argument of type 'NoneType' is not iterable
calibre 7.23 embedded-python: False Linux-6.12.25_1-x86_64-with-glibc2.41 Linux ('64bit', 'ELF') ('Linux', '6.12.25_1', '#1 SMP PREEMPT_DYNAMIC Sun Apr 27 00:10:34 UTC 2025') Python 3.13.3 Interface language: None EXE path: /usr/bin/python3 Successfully initialized third party plugins: Gather KFX-ZIP (from KFX Input) (2, 23, 0) && Package KFX (from KFX Input) (2, 23, 0) && Apple Books covers (0, 2, 0) && Count Pages (1, 13, 6) && Goodreads (1, 8, 3) && KFX metadata reader (from KFX Input) (2, 23, 0) && From KFX (2, 23, 0) && KFX Input (2, 23, 0) && KOReader Sync (0, 7, 1) && Kindle hi-res covers (0, 5, 1) && Kobo Metadata (1, 10, 1) && Kobo Utilities (2, 22, 1) && KoboTouchExtended (3, 7, 3) && Obok DeDRM (10, 0, 3) Traceback (most recent call last): File "calibre_plugins.koreader.action", line 1128, in run sidecar_contents = self.action.get_sidecar( device, sidecar_path) File "calibre_plugins.koreader.action", line 448, in get_sidecar parsed_contents = parse_sidecar_lua(decoded_contents) File "calibre_plugins.koreader.action", line 154, in parse_sidecar_lua if 'bookmarks' in decoded_lua: ^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument of type 'NoneType' is not iterable
Relevant code below. Seems like there's an issue with the decoding the lua sidecar. Would be helpful to get a debug log (run calibre in debug and provide output with error before the crash using calibre-debug -g) to confirm the issue as it should print could not decode sidecar_lua. Fix would be to figure out what actually caused the decode issue and address that... or something like moving the bookmark stuff to the try or maybe if decoded_lua.get( 'bookmarks', None) or similar
try:
clean_lua = re.sub('^[^{]*', '', sidecar_lua).strip()
decoded_lua = lua.decode(clean_lua)
except:
debug_print('could not decode sidecar_lua')
decoded_lua = None
if 'bookmarks' in decoded_lua:
if type(decoded_lua['bookmarks']) is list:
decoded_lua['bookmarks'] = {
# Starts from 1
i+1: bookmark for i, bookmark in enumerate(decoded_lua['bookmarks'])}
Attached is "calibre-debug -g" output..
Did the error occur when this was produced? I don't see any relevant stacktrace in the log?
Also usually you can reproduce the issue with just importing lua file into your device. So worth sharing that "deleted" book (actually lua file)
FOUND IT!
Somehow an older read book had an empty (null 0 byte size) sidecar lua file (don't know what caused that) -- was able to identify the book from the calibre-debug log.
Without the debug output, what threw me was the book listed on the progress bar is the prior book to the error causing book.
Thanks for all your assistance.