From 3fc317c9571c13261782a42c31a629c9b843d45f Mon Sep 17 00:00:00 2001 From: QingXia-Ela Date: Sun, 12 May 2024 23:12:31 +0800 Subject: [PATCH] fix: prevent error appear when check latest version fail(#11012) --- .changeset/warm-schools-applaud.md | 5 ++++ packages/astro/src/core/dev/dev.ts | 42 ++++++++++++++++-------------- 2 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 .changeset/warm-schools-applaud.md diff --git a/.changeset/warm-schools-applaud.md b/.changeset/warm-schools-applaud.md new file mode 100644 index 000000000000..7691b7692d4b --- /dev/null +++ b/.changeset/warm-schools-applaud.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +fix: prevent error appear when check latest version fail(#11012) diff --git a/packages/astro/src/core/dev/dev.ts b/packages/astro/src/core/dev/dev.ts index e0a25d75b8cd..89711a5f844d 100644 --- a/packages/astro/src/core/dev/dev.ts +++ b/packages/astro/src/core/dev/dev.ts @@ -48,29 +48,33 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise { if (shouldCheck) { - const version = await fetchLatestAstroVersion(restart.container.settings.preferences); + try { + const version = await fetchLatestAstroVersion(restart.container.settings.preferences); - if (gt(version, currentVersion)) { - // Only update the latestAstroVersion if the latest version is greater than the current version, that way we don't need to check that again - // whenever we check for the latest version elsewhere - restart.container.settings.latestAstroVersion = version; + if (gt(version, currentVersion)) { + // Only update the latestAstroVersion if the latest version is greater than the current version, that way we don't need to check that again + // whenever we check for the latest version elsewhere + restart.container.settings.latestAstroVersion = version; - const sameMajor = major(version) === major(currentVersion); - const sameMinor = minor(version) === minor(currentVersion); - const patchDistance = patch(version) - patch(currentVersion); + const sameMajor = major(version) === major(currentVersion); + const sameMinor = minor(version) === minor(currentVersion); + const patchDistance = patch(version) - patch(currentVersion); - if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) { - // Don't bother the user with a log if they're only a few patch versions behind - // We can still tell them in the dev toolbar, which has a more opt-in nature - return; - } + if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) { + // Don't bother the user with a log if they're only a few patch versions behind + // We can still tell them in the dev toolbar, which has a more opt-in nature + return; + } - logger.warn( - 'SKIP_FORMAT', - await msg.newVersionAvailable({ - latestVersion: version, - }) - ); + logger.warn( + 'SKIP_FORMAT', + await msg.newVersionAvailable({ + latestVersion: version, + }) + ); + } + } catch (e) { + // Do nothing, check version fail shouldn't block server running. } } });