From 9a7518eba13857edd1ccf3bc2c1c33715005ea74 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Thu, 28 Mar 2024 01:57:17 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20CLI=20move=20error=20ha?= =?UTF-8?q?ndling=20code=20from=20handler=20to=20runWithPlatform?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/cli/cmds/search_cmds/index-all.ts | 21 +++++++------------ .../node/src/cli/lib/run-with-platform.ts | 9 ++++++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tdrive/backend/node/src/cli/cmds/search_cmds/index-all.ts b/tdrive/backend/node/src/cli/cmds/search_cmds/index-all.ts index 39d97c63..13f43336 100644 --- a/tdrive/backend/node/src/cli/cmds/search_cmds/index-all.ts +++ b/tdrive/backend/node/src/cli/cmds/search_cmds/index-all.ts @@ -83,19 +83,14 @@ const command: yargs.CommandModule = { : "info" : undefined, async () => { - try { - for (const repositoryName of repositories) - await RepositoryNameToCTOR.get(repositoryName) - .ctor(platform, { - spinner, - repairEntities: !!argv.repairEntities, - filterDocumentsByUserEMail, - }) - .run(); - } catch (err) { - spinner.fail(err.stack || err); - return 1; - } + for (const repositoryName of repositories) + await RepositoryNameToCTOR.get(repositoryName) + .ctor(platform, { + spinner, + repairEntities: !!argv.repairEntities, + filterDocumentsByUserEMail, + }) + .run(); }, ); }); diff --git a/tdrive/backend/node/src/cli/lib/run-with-platform.ts b/tdrive/backend/node/src/cli/lib/run-with-platform.ts index ddc1b3ba..8b02bb37 100644 --- a/tdrive/backend/node/src/cli/lib/run-with-platform.ts +++ b/tdrive/backend/node/src/cli/lib/run-with-platform.ts @@ -29,8 +29,13 @@ export default async function runWithPlatform( const platform = await tdrive.run(config.get("services")); await gr.doInit(platform); spinner.succeed("Platform: started"); - const exitCode = await handler({ spinner, config, platform }); - if (typeof exitCode === "number") process.exitCode = exitCode; + try { + 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..."); await platform.stop(); spinner.succeed("Platform: shutdown");