Corrupted collection import additional tooling

I’ve used Anki almost every day for 3 years and I’ve exported my collection from a possibly dying hard drive. Long story short the collection I have is the collection I have (colpkg) and I’m trying to put it on a different computer with a possibly newer version of Anki. It is failing to import complaining about the first utf-8 byte at some point in the file.

The problem is, I can’t see really any more information than that at the point of error. It’s giving me a line number for the script (not the point of corruption in the file or unzipped stream). There is a suggestion to run Tools->Check Database. However this invokes a check on my freshly created empty collection.

I’m posting in development because I sense that the function I need just isn’t there, and I happen to be a well seasoned developer. I need to recover my collection but my goal is to do so by adding some diagnostic or moreso bridging the existing diagnostic tools over to the collection import. Once I know exactly whats wrong, I’ll deal with the collection manually. But in the mean time, I was hoping to contribute to this project I’ve used so much.

I have not cloned the git yet but I wanted to post for help here, in case there was something simple I was overlooking, and also if someone who has worked on the import/export or corrupted collections can drop any helpful starting points, like a basic plan of attack as I have no knowledge of the code base.

Thanks for reading,
soup

Anki 2.1.13 (3ba55990) Python 3.13.2 Qt 5.15.16 PyQt 5.15.10
Platform: Linux
Flags: frz=False ao=False sv=?

Caught exception:
File “/usr/share/anki/aqt/main.py”, line 908, in onImport
aqt.importing.onImport(self)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/usr/share/anki/aqt/importing.py”, line 286, in onImport
importFile(mw, file)
~~~~~~~~~~^^^^^^^^^^
File “/usr/share/anki/aqt/importing.py”, line 334, in importFile
if not setupApkgImport(mw, importer):
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File “/usr/share/anki/aqt/importing.py”, line 388, in setupApkgImport
replaceWithApkg(mw, importer.file, mw.restoringBackup)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/share/anki/aqt/importing.py”, line 391, in replaceWithApkg
mw.unloadCollection(lambda: _replaceWithApkg(mw, file, backup))
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/share/anki/aqt/main.py”, line 379, in unloadCollection
self.closeAllWindows(callback)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File “/usr/share/anki/aqt/main.py”, line 632, in closeAllWindows
aqt.dialogs.closeAll(onsuccess)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File “/usr/share/anki/aqt/init.py”, line 95, in closeAll
onsuccess()
~~~~~~~~~^^
File “/usr/share/anki/aqt/main.py”, line 377, in callback
onsuccess()
~~~~~~~~~^^
File “/usr/share/anki/aqt/importing.py”, line 391, in
mw.unloadCollection(lambda: _replaceWithApkg(mw, file, backup))
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File “/usr/share/anki/aqt/importing.py”, line 419, in _replaceWithApkg
json.loads(z.read(“media”).decode(“utf8”)).items()):
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
<class ‘UnicodeDecodeError’>: ‘utf-8’ codec can’t decode byte 0xb5 in position 1: invalid start byte

Is 2.1.13 the newer version you’re trying to import into? It’s already very old, in terms of how dramatically anki has changed since then. And if the original collection is from an even older version of anki, it’s going to be tricky. The code referenced in the traceback doesn’t exist anymore on main, having being rewritten in rust

1 Like

@llama
I installed fresh on a different distro. The original is Arch but wasn’t updated in a while, “new” one is openSUSE Tumbleweed (rolling release, daily updates) and just assumed it was a fairly recent version. That seems to have been a bad assumption so perhaps there’s no active package maintainer on SUSE. If it’s that old, then my “old” one that wasn’t updated in a few months may even be newer than my “new” one.

Thanks for the heads up. I’ll start by getting a not terribly old version then see where we’re at haha.

1 Like

Historical trivia: Is Anki too hard to build? (Or, make life easier for packagers.) · Issue #1378 · ankitects/anki · GitHub

1 Like

Oh boy.. skimmed that thread.. I did not realize that was a soft spot :sweat_smile:
I guess that explains that. Good news though, I cloned, made sure I had ninja and rustup, and it built first try. Also, the fresh build was able to import my collection. I honestly assumed that the file really was corrupted given that I had pulled it from a failing hard drive.

Sorry about the confusion. Since I don’t need to fix my collection that means I don’t need better import error diagnostics (can’t even see the error screen anymore). But now that I’ve bugged you guys and got it building, I’ll see if there’s any tickets I can take a stab at. I might even see about helping with the SUSE package. It’s still in the repo but just out of date, so it would be nice not to see it fall completely out.

2 Likes

Not sure what needs to be done to package apps for SUSE, but building the latest version of anki is as easy as cloning the repo and running ./run.

Maybe that’ll help in finding fellow maintainers for SUSE too.