diff --git a/packages/cli/index.ts b/packages/cli/index.ts index bbc22a46..30b2cd59 100755 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -35,7 +35,13 @@ type Options = { async function main() { // Start a version check in the background - const cliVersionCheckPromise = checkLatestVersion(); + // unhandled promise rejection can happen even without the `await` + // so we need a `catch` here. + const cliVersionCheckPromise = checkLatestVersion().catch(() => ({ + latestVersion: "unknown", + currentVersion: "unknown", + isNewerAvailable: false, + })); // Must load tokens and config before anything else await authStore.initialize(); @@ -91,19 +97,15 @@ async function main() { } } - try { - const { latestVersion, currentVersion, isNewerAvailable } = - await cliVersionCheckPromise; + const { latestVersion, currentVersion, isNewerAvailable } = + await cliVersionCheckPromise; - if (isNewerAvailable) { - console.info( - `A new version of the CLI is available: ${chalk.yellow( - currentVersion, - )} -> ${chalk.green(latestVersion)}. Update to ensure you have the latest features and bug fixes.`, - ); - } - } catch { - // Ignore errors + if (isNewerAvailable) { + console.info( + `A new version of the CLI is available: ${chalk.yellow( + currentVersion, + )} -> ${chalk.green(latestVersion)}. Update to ensure you have the latest features and bug fixes.`, + ); } if (debug) { diff --git a/packages/cli/utils/version.ts b/packages/cli/utils/version.ts index d29cf22d..116cf48b 100644 --- a/packages/cli/utils/version.ts +++ b/packages/cli/utils/version.ts @@ -55,7 +55,6 @@ export async function checkLatest() { const latestVersion = await getLatestVersionFromNpm(packageName); const isNewerAvailable = gt(latestVersion, currentVersion); - return { currentVersion, latestVersion,