Skip to content

Commit

Permalink
Move error handling to better place
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Aug 27, 2023
1 parent 2856366 commit f25d338
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
4 changes: 3 additions & 1 deletion packages/node-core/src/configure/ProjectUpgrade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export class ProjectUpgradeSevice<P extends ISubqueryProject = ISubqueryProject>
}

// 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`
Expand Down
40 changes: 18 additions & 22 deletions packages/node-core/src/configure/configure.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,24 @@ export async function registerApp<P extends ISubqueryProject>(
});

const createParentProject = async (cid: string): Promise<P> => {
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);
Expand Down

0 comments on commit f25d338

Please sign in to comment.