From 5846d4d5420042b83e125c343a5ce4c952c4e14f Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Thu, 21 Nov 2024 11:36:37 +0100 Subject: [PATCH] Properly handle error while loading packages --- main.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 5af1635..eedb026 100755 --- a/main.js +++ b/main.js @@ -78,11 +78,17 @@ export async function main() { .command('list') .description('List packages from registries') .action(async () => { - const packageList = await packageManager.getPackageList(); - const packages = packageList ? packageList.map((pkg) => `📦 ${pkg.name}`).join('\n') : null; - - if (packages) { - console.log(packages); + try { + const packageList = await packageManager.getPackageList(); + const packages = packageList ? packageList.map((pkg) => `📦 ${pkg.name}`).join('\n') : null; + if (packages && packages.length > 0) { + console.log(packages); + } else { + console.log("🤷 No packages found.") + } + } catch (error) { + console.error(error.message); + process.exit(1); } });