♻️ CLI move error handling code from handler to runWithPlatform

This commit is contained in:
Eric Doughty-Papassideris
2024-03-28 01:57:17 +01:00
committed by ericlinagora
parent aac4caafaa
commit 9a7518eba1
2 changed files with 15 additions and 15 deletions
@@ -83,19 +83,14 @@ const command: yargs.CommandModule<unknown, unknown> = {
: "info" : "info"
: undefined, : undefined,
async () => { async () => {
try { for (const repositoryName of repositories)
for (const repositoryName of repositories) await RepositoryNameToCTOR.get(repositoryName)
await RepositoryNameToCTOR.get(repositoryName) .ctor(platform, {
.ctor(platform, { spinner,
spinner, repairEntities: !!argv.repairEntities,
repairEntities: !!argv.repairEntities, filterDocumentsByUserEMail,
filterDocumentsByUserEMail, })
}) .run();
.run();
} catch (err) {
spinner.fail(err.stack || err);
return 1;
}
}, },
); );
}); });
@@ -29,8 +29,13 @@ export default async function runWithPlatform(
const platform = await tdrive.run(config.get("services")); const platform = await tdrive.run(config.get("services"));
await gr.doInit(platform); await gr.doInit(platform);
spinner.succeed("Platform: started"); spinner.succeed("Platform: started");
const exitCode = await handler({ spinner, config, platform }); try {
if (typeof exitCode === "number") process.exitCode = exitCode; const exitCode = await handler({ spinner, config, platform });
if (typeof exitCode === "number") process.exitCode = exitCode;
} catch (err) {
spinner.fail(err.stack || err);
process.exitCode = 1;
}
spinner.start("Platform: shutting down..."); spinner.start("Platform: shutting down...");
await platform.stop(); await platform.stop();
spinner.succeed("Platform: shutdown"); spinner.succeed("Platform: shutdown");