diff --git a/package.json b/package.json index 08b38ed5..3a791fa8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ardrive-core-js", - "version": "2.0.5", + "version": "2.0.6", "description": "ArDrive Core contains the essential back end application features to support the ArDrive CLI and Desktop apps, such as file management, Permaweb upload/download, wallet management and other common functions.", "main": "./lib/exports.js", "types": "./lib/exports.d.ts", diff --git a/src/arfs/arfsdao.ts b/src/arfs/arfsdao.ts index f7ecd05b..7b25d7bc 100644 --- a/src/arfs/arfsdao.ts +++ b/src/arfs/arfsdao.ts @@ -1528,16 +1528,31 @@ export class ArFSDAO extends ArFSDAOAnonymous { const { edges } = transactions; hasNextPage = transactions.pageInfo.hasNextPage; - const folders: Promise[] = edges.map(async (edge: GQLEdgeInterface) => { - cursor = edge.cursor; - const { node } = edge; - const folderBuilder = ArFSPrivateFolderBuilder.fromArweaveNode(node, this.gatewayApi, driveKey); - // Build the folder so that we don't add something invalid to the cache - const folder = await folderBuilder.build(node); - const cacheKey = { folderId: folder.entityId, owner, driveKey }; - return this.caches.privateFolderCache.put(cacheKey, Promise.resolve(folder)); + const folderPromises: Promise[] = edges.map(async (edge: GQLEdgeInterface) => { + try { + cursor = edge.cursor; + const { node } = edge; + const folderBuilder = ArFSPrivateFolderBuilder.fromArweaveNode(node, this.gatewayApi, driveKey); + // Build the folder so that we don't add something invalid to the cache + const folder = await folderBuilder.build(node); + const cacheKey = { folderId: folder.entityId, owner, driveKey }; + return this.caches.privateFolderCache.put(cacheKey, Promise.resolve(folder)); + } catch (e) { + // If the folder is broken, skip it + if (e instanceof SyntaxError) { + console.error(`Error building folder. Skipping... Error: ${e}`); + return null; + } + + throw e; + } }); - allFolders.push(...(await Promise.all(folders))); + + const folders = await Promise.all(folderPromises); + + // Filter out null values + const validFolders = folders.filter((f) => f !== null) as ArFSPrivateFolder[]; + allFolders.push(...(await Promise.all(validFolders))); } return latestRevisionsOnly ? allFolders.filter(latestRevisionFilter) : allFolders; diff --git a/src/arfs/arfsdao_anonymous.ts b/src/arfs/arfsdao_anonymous.ts index 8e811d53..024e2deb 100644 --- a/src/arfs/arfsdao_anonymous.ts +++ b/src/arfs/arfsdao_anonymous.ts @@ -304,15 +304,32 @@ export class ArFSDAOAnonymous extends ArFSDAOType { const { edges } = transactions; hasNextPage = transactions.pageInfo.hasNextPage; - const folders: Promise[] = edges.map(async (edge: GQLEdgeInterface) => { + const folderPromises = edges.map(async (edge: GQLEdgeInterface) => { const { node } = edge; cursor = edge.cursor; - const folderBuilder = ArFSPublicFolderBuilder.fromArweaveNode(node, this.gatewayApi); - const folder = await folderBuilder.build(node); - const cacheKey = { folderId: folder.entityId, owner }; - return this.caches.publicFolderCache.put(cacheKey, Promise.resolve(folder)); + try { + const folderBuilder = ArFSPublicFolderBuilder.fromArweaveNode(node, this.gatewayApi); + const folder = await folderBuilder.build(node); + const cacheKey = { folderId: folder.entityId, owner }; + await this.caches.publicFolderCache.put(cacheKey, Promise.resolve(folder)); + return folder; + } catch (e) { + // If the folder is broken, skip it + if (e instanceof SyntaxError) { + console.error(`Error building folder. Skipping... Error: ${e}`); + return null; + } + + throw e; + } }); - allFolders.push(...(await Promise.all(folders))); + + const folders = await Promise.all(folderPromises); + + // Filter out null values + const validFolders = folders.filter((folder) => folder !== null) as ArFSPublicFolder[]; + + allFolders.push(...validFolders); } return latestRevisionsOnly ? allFolders.filter(latestRevisionFilter) : allFolders; } @@ -338,6 +355,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType { // Fetch all of the folder entities within the drive const driveIdOfFolder = folder.driveId; + const allFolderEntitiesOfDrive = await this.getAllFoldersOfPublicDrive({ driveId: driveIdOfFolder, owner, @@ -375,6 +393,7 @@ export class ArFSDAOAnonymous extends ArFSDAOType { } const entitiesWithPath = children.map((entity) => publicEntityWithPathsFactory(entity, hierarchy)); + return entitiesWithPath; }