From 72a588c2370c17e415b24fe389efdafb3c84e90b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 27 Jan 2025 23:22:51 +0100 Subject: [PATCH] fix: only print message for `UsageError`s (#602) --- sources/main.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sources/main.ts b/sources/main.ts index 8849e8832..1fa13d40f 100644 --- a/sources/main.ts +++ b/sources/main.ts @@ -1,4 +1,5 @@ import {BaseContext, Builtins, Cli} from 'clipanion'; +import type {UsageError} from 'clipanion'; import {version as corepackVersion} from '../package.json'; @@ -79,9 +80,17 @@ export async function runMain(argv: Array) { process.exitCode ??= code; } } else { - await engine.executePackageManagerRequest(request, { - cwd: process.cwd(), - args: restArgs, - }); + try { + await engine.executePackageManagerRequest(request, { + cwd: process.cwd(), + args: restArgs, + }); + } catch (error: UsageError | any) { + if (error?.name === `UsageError`) { + console.error(error.message); + process.exit(1); + } + throw error; + } } }