Skip to content

Commit c4030e2

Browse files
authored
fix: version check can cause failures (#478)
If the version check is blocked for some reason, the process can fail. Apparently promise rejections can happen without `await` calls.
1 parent bfd3e4e commit c4030e2

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

packages/cli/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ type Options = {
3535

3636
async function main() {
3737
// Start a version check in the background
38-
const cliVersionCheckPromise = checkLatestVersion();
38+
// unhandled promise rejection can happen even without the `await`
39+
// so we need a `catch` here.
40+
const cliVersionCheckPromise = checkLatestVersion().catch(() => ({
41+
latestVersion: "unknown",
42+
currentVersion: "unknown",
43+
isNewerAvailable: false,
44+
}));
3945

4046
// Must load tokens and config before anything else
4147
await authStore.initialize();
@@ -91,19 +97,15 @@ async function main() {
9197
}
9298
}
9399

94-
try {
95-
const { latestVersion, currentVersion, isNewerAvailable } =
96-
await cliVersionCheckPromise;
100+
const { latestVersion, currentVersion, isNewerAvailable } =
101+
await cliVersionCheckPromise;
97102

98-
if (isNewerAvailable) {
99-
console.info(
100-
`A new version of the CLI is available: ${chalk.yellow(
101-
currentVersion,
102-
)} -> ${chalk.green(latestVersion)}. Update to ensure you have the latest features and bug fixes.`,
103-
);
104-
}
105-
} catch {
106-
// Ignore errors
103+
if (isNewerAvailable) {
104+
console.info(
105+
`A new version of the CLI is available: ${chalk.yellow(
106+
currentVersion,
107+
)} -> ${chalk.green(latestVersion)}. Update to ensure you have the latest features and bug fixes.`,
108+
);
107109
}
108110

109111
if (debug) {

packages/cli/utils/version.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export async function checkLatest() {
5555

5656
const latestVersion = await getLatestVersionFromNpm(packageName);
5757
const isNewerAvailable = gt(latestVersion, currentVersion);
58-
5958
return {
6059
currentVersion,
6160
latestVersion,

0 commit comments

Comments
 (0)