#5732·anki

A call to `import_collection_package` can unexpectedly return `SyncOtherError`

Author: david-allisonCreated Sep 29, 2026Updated Sep 29, 2026
Failure at rslib/src/backend/import_export.rs:79:9:

    assertion `left == right` failed
      left: SyncOtherError
     right: ImportError

Test result: 0 passed; 1 failed; 743 filtered out.

patch
Subject: [PATCH] test: expect an import error for an invalid collection package

Reproduced on upstream ankitects/anki main at
d1d484c8249a8266a6fe9203694f9087726c6ba2:

    cargo test --offline --locked -p anki --lib \
      backend::import_export::tests::invalid_collection_package_returns_import_error \
      -- --exact --nocapture

---
diff --git a/rslib/src/backend/import_export.rs b/rslib/src/backend/import_export.rs
--- a/rslib/src/backend/import_export.rs
+++ b/rslib/src/backend/import_export.rs
@@ -36,3 +36,46 @@
         )
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use anki_io::write_file;
+    use anki_proto::backend::backend_error::Kind;
+    use anki_proto::import_export::ImportCollectionPackageRequest;
+    use tempfile::tempdir;
+
+    use super::*;
+
+    #[test]
+    fn invalid_collection_package_returns_import_error() -> Result<()> {
+        let dir = tempdir()?;
+        let backup_path = dir.path().join("invalid.colpkg");
+        write_file(&backup_path, b"not a zip archive")?;
+        let backend = Backend::new(I18n::new(&["en"]), false);
+
+        let error = backend
+            .import_collection_package(ImportCollectionPackageRequest {
+                col_path: dir
+                    .path()
+                    .join("collection.anki2")
+                    .to_string_lossy()
+                    .into_owned(),
+                backup_path: backup_path.to_string_lossy().into_owned(),
+                media_folder: dir
+                    .path()
+                    .join("collection.media")
+                    .to_string_lossy()
+                    .into_owned(),
+                media_db: dir
+                    .path()
+                    .join("collection.media.db2")
+                    .to_string_lossy()
+                    .into_owned(),
+            })
+            .unwrap_err()
+            .into_protobuf(backend.i18n());
+
+        assert_eq!(error.kind(), Kind::ImportError);
+        Ok(())
+    }
+}