Skip to content

Commit

Permalink
fix: prevent error appear when check latest version fail(withastro#11012
Browse files Browse the repository at this point in the history
)
  • Loading branch information
QingXia-Ela committed May 12, 2024
1 parent a78fa26 commit 3fc317c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-schools-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

fix: prevent error appear when check latest version fail(#11012)
42 changes: 23 additions & 19 deletions packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,33 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS
// Don't await this, we don't want to block the dev server from starting
shouldCheckForUpdates(restart.container.settings.preferences).then(async (shouldCheck) => {
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.
}
}
});
Expand Down

0 comments on commit 3fc317c

Please sign in to comment.