Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[photos][web] Include collection IDs in sync decryption errors

AswinAsok52dff722c195
diff --git a/web/packages/new/photos/services/collection-decryption-error.ts b/web/packages/new/photos/services/collection-decryption-error.ts
new file mode 100644
index 0000000000..06d5599511
--- /dev/null
+++ b/web/packages/new/photos/services/collection-decryption-error.ts
@@ -0,0 +1,8 @@
+export const collectionDecryptionError = (
+ collectionID: number,
+ cause: unknown,
+) =>
+ new Error(
+ `${cause instanceof Error ? cause.message : String(cause)} (collectionID: ${collectionID})`,
+ { cause },
+ );
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts
index bb373c5594..3e67551bad 100644
--- a/web/packages/new/photos/services/collection.ts
+++ b/web/packages/new/photos/services/collection.ts
@@ -35,6 +35,7 @@ import {
import { ensureMasterKeyFromSession } from "ente-new/photos/services/account-keys";
import { batch, splitByPredicate } from "ente-utils/array";
import { z } from "zod";
+import { collectionDecryptionError } from "./collection-decryption-error";
import { batched, type UpdateMagicMetadataRequest } from "./file";
import {
removeCollectionIDLastSyncTime,
@@ -115,8 +116,16 @@ const createCollection = async (
return decryptRemoteKeyAndCollection(remoteCollection);
};
-const decryptRemoteKeyAndCollection = async (collection: RemoteCollection) =>
- decryptRemoteCollection(collection, await decryptCollectionKey(collection));
+const decryptRemoteKeyAndCollection = async (collection: RemoteCollection) => {
+ try {
+ return await decryptRemoteCollection(
+ collection,
+ await decryptCollectionKey(collection),
+ );
+ } catch (e) {
+ throw collectionDecryptionError(collection.id, e);
+ }
+};
const decryptCollectionKey = async (
collection: RemoteCollection,
@@ -260,7 +269,9 @@ export const pullCollectionFiles = async (
const file = await decryptRemoteFile(
change,
collection.key,
- );
+ ).catch((e: unknown) => {
+ throw collectionDecryptionError(collection.id, e);
+ });
await clearCachedThumbnailIfContentChanged(
thisCollectionFilesByID.get(change.id),
file,
diff --git a/web/packages/new/photos/services/trash.ts b/web/packages/new/photos/services/trash.ts
index 900cd1b663..26d286f98a 100644
--- a/web/packages/new/photos/services/trash.ts
+++ b/web/packages/new/photos/services/trash.ts
@@ -9,6 +9,7 @@ import {
import { fileCreationTime } from "ente-media/file-metadata";
import { z } from "zod";
import { getCollectionByID } from "./collection";
+import { collectionDecryptionError } from "./collection-decryption-error";
import {
savedTrashItemCollectionKeys,
savedTrashItems,
@@ -78,7 +79,12 @@ export const pullTrash = async (
}
trashItemsByID.set(fileID, {
...change,
- file: await decryptRemoteFile(change.file, collectionKey),
+ file: await decryptRemoteFile(
+ change.file,
+ collectionKey,
+ ).catch((e: unknown) => {
+ throw collectionDecryptionError(collectionID, e);
+ }),
});
}
}