From 998ac54013491b1ce402d64cbd164231d585344d Mon Sep 17 00:00:00 2001 From: Scott Twiname Date: Fri, 25 Aug 2023 10:07:48 +1200 Subject: [PATCH] Move error handling to better place --- .../src/configure/ProjectUpgrade.service.ts | 4 +- .../src/configure/configure.module.ts | 40 +++++++++---------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/node-core/src/configure/ProjectUpgrade.service.ts b/packages/node-core/src/configure/ProjectUpgrade.service.ts index efb8923da9..05eaf70296 100644 --- a/packages/node-core/src/configure/ProjectUpgrade.service.ts +++ b/packages/node-core/src/configure/ProjectUpgrade.service.ts @@ -204,7 +204,9 @@ export class ProjectUpgradeSevice

} // Load the next project and repeat - const nextProject = await loadProject(currentProject.parent.reference); + const nextProject = await loadProject(currentProject.parent.reference).catch((e) => { + throw new Error(`Failed to load parent project with cid: ${currentProject.parent?.reference}. ${e}`); + }); if (nextProject.parent && nextProject.parent.block > currentProject.parent.block) { throw new Error( `Parent project ${currentProject.parent.reference} has a block height that is greater than the current project` diff --git a/packages/node-core/src/configure/configure.module.ts b/packages/node-core/src/configure/configure.module.ts index 8d0441b881..db45878a8a 100644 --- a/packages/node-core/src/configure/configure.module.ts +++ b/packages/node-core/src/configure/configure.module.ts @@ -146,28 +146,24 @@ export async function registerApp

( }); const createParentProject = async (cid: string): Promise

=> { - try { - cid = `ipfs://${cid}`; - const reader = await ReaderFactory.create(cid, { - ipfs: config.ipfs, - }); - return createProject( - cid, - await reader.getProjectSchema(), - reader, - await getCachedRoot(reader, config.root), - omitBy( - // Apply the network endpoint and dictionary from the source project to the parent projects if they are not defined in the config - { - endpoint: config.networkEndpoints ?? project.network.endpoint, - dictionary: config.networkDictionary ?? project.network.dictionary, - }, - isNil - ) - ); - } catch (e) { - throw new Error(`Failed to load parent project with cid: ${cid}. ${e}`); - } + cid = `ipfs://${cid}`; + const reader = await ReaderFactory.create(cid, { + ipfs: config.ipfs, + }); + return createProject( + cid, + await reader.getProjectSchema(), + reader, + await getCachedRoot(reader, config.root), + omitBy( + // Apply the network endpoint and dictionary from the source project to the parent projects if they are not defined in the config + { + endpoint: config.networkEndpoints ?? project.network.endpoint, + dictionary: config.networkDictionary ?? project.network.dictionary, + }, + isNil + ) + ); }; const projectUpgradeService = await ProjectUpgradeSevice.create(project, createParentProject);